Created
July 5, 2017 07:02
-
-
Save niisar/582288322179ff5365250152fd9ade12 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading.Tasks; | |
namespace Aps.ManageIT | |
{ | |
public class UpdateOrderNo | |
{ | |
public string ContentTypeId { get; set; } | |
public string AttributeSetId { get; set; } | |
public string SubObjectId { get; set; } | |
public int startOrderNo { get; set; } | |
public int endOrderNo { get; set; } | |
//public string CurrentAttributeId { get; set; } | |
//public string PreviousAttributeId { get; set; } | |
} | |
public class UpdateSearcInterfaceOrderNo : UpdateOrderNo | |
{ | |
public SearchInterfaceType SearchInterfaceType { get; set; } | |
} | |
public class UpdateUserInterfaceOrderNo : UpdateOrderNo | |
{ | |
public String UserInterfaceType { get; set; } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<bool> UpdateOrderNo(UpdateOrderNo updateOrderNo) | |
{ | |
bool result = true; | |
try | |
{ | |
//var allRecord = await repContentObject.GetAllAsync(contentObjectCollection); | |
var contentObjectList = await repContentObject.GetAllAsync(contentObjectCollection); | |
//var campaign = (await GetAllCampaigns(updateOrderNo.ContentTypeId)); | |
bool isUpdateRequired = false; | |
//var allRecord = contentObjectList.Where(x => x.ContentTypeId == updateOrderNo.ContentTypeId && x.ObjectType.ToLower()=="jobit").ToList(); | |
// var allRecord = await GetAllContentObjectByContentTypeAsync(updateOrderNo.ContentTypeId); | |
if (!isUpdateRequired && contentObjectList != null && contentObjectList.Count() > 0) | |
{ | |
if (updateOrderNo.startOrderNo != 0 && updateOrderNo.endOrderNo != 0) | |
{ | |
bool seqChanged = false; | |
int start = 0; | |
int end = 0; | |
if (updateOrderNo.startOrderNo > updateOrderNo.endOrderNo) | |
{ | |
seqChanged = true; | |
start = updateOrderNo.endOrderNo; | |
end = updateOrderNo.startOrderNo; | |
} | |
else | |
{ | |
seqChanged = false; | |
start = updateOrderNo.startOrderNo; | |
end = updateOrderNo.endOrderNo; | |
} | |
int incrementNO = start; | |
var changedObjects = contentObjectList.Where(x => x.OrderNo >= start && x.OrderNo <= end).ToList(); | |
foreach (var obj in changedObjects) | |
{ | |
contentObjectList.Where(x => x._id == obj._id).FirstOrDefault().OrderNo = (obj.OrderNo == updateOrderNo.startOrderNo) ? updateOrderNo.endOrderNo : | |
(seqChanged == true) ? ++incrementNO : incrementNO++; | |
} | |
isUpdateRequired = true; | |
} | |
} | |
foreach (var item in contentObjectList) | |
{ | |
await repContentObject.UpdateDocumentAsync(item._id.ToString(), item, contentObjectCollection); | |
} | |
// await repContentObject.UpdateDocumentAsync(allRecord., item, contentObjectCollection); | |
//if (await CheckforCurrentVerison(campaign._id.ToString(), campaign.Version) && isUpdateRequired) | |
//{ | |
// await repContentObject.UpdateDocumentAsync(allRecord_id.ToString(), allRecord, contentObjectCollection); | |
//} | |
} | |
catch (MongoException ex) | |
{ | |
errorRepository.LogError(new Aps.ManageIT.Repository.MongoDB.Models.ErrorMessage(ex)); | |
result = false; | |
} | |
catch (Exception ex) | |
{ | |
errorRepository.LogError(new Aps.ManageIT.Repository.MongoDB.Models.ErrorMessage(ex)); | |
result = false; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment