niisar
7/5/2017 - 7:02 AM

UpdateOrderNo-Model.cs

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;
        }
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; }
    }
}