Пример #1
0
 public static List <VipCardDetailModel> GetVipCardDetailForEdit(string activityId, int clientId)
 {
     try
     {
         var cardId       = DalVipCard.GetVipCardIdByActivityId(activityId);
         var cardDetails  = DalVipCard.GetVipCardDetailsByActivityId(cardId).ToList();
         var batchDetails = DalVipCard.GetBatchesByClientId(clientId).ToList();
         var result       = (from a in batchDetails
                             join b in cardDetails on a.BatchId equals b.BatchId into temp
                             from b in temp.DefaultIfEmpty()
                             select new VipCardDetailModel
         {
             _checked = b != null,
             Stock = a.Stock,
             EndDate = a.EndDate,
             StartDate = a.StartDate,
             UseRange = a.UseRange,
             SalePrice = a.SalePrice,
             CardValue = a.CardValue,
             CardName = a.CardName,
             BatchId = a.BatchId,
             ClientName = a.ClientName,
             ClientId = a.ClientId
         }).ToList()
         ;
         return(result);
     }
     catch (Exception ex)
     {
         logger.Error(ex.Message, ex);
     }
     return(new List <VipCardDetailModel>
     {
     });
 }
Пример #2
0
        public static bool UpdateVipCardModelAndDetails(List <VipCardDetailModel> details, string activityName, string activityId, int clientId)
        {
            bool result = true;

            using (var dbHelper = new SqlDbHelper(ConnectionHelper.GetDecryptConn("Gungnir")))
            {
                try
                {
                    //dbHelper.BeginTransaction();
                    var clientName   = GetBatchesByClientId(clientId).Select(r => r.ClientName).FirstOrDefault();
                    var detailbefore = DalVipCard.GetVipCardDetailsByActivityId(activityId);
                    var cardId       = DalVipCard.GetVipCardIdByActivityId(activityId);
                    var batchIds     = details.Select(r => r.BatchId).ToList();

                    var IsNeedUpdateAct = false;

                    #region log

                    var batchIdBefores = detailbefore.Select(r => r.BatchId).ToList();
                    var actNamebefore  = detailbefore.Select(r => r.ActivityName).FirstOrDefault();
                    var deleteBatches  = batchIdBefores.Except(batchIds);
                    var addBatches     = batchIds.Except(batchIdBefores);
                    if (actNamebefore != activityName)
                    {
                        IsNeedUpdateAct = true;
                        var before = actNamebefore;
                        var after  = activityName;
                        OpertionLogs(OpertionType.EditEdit, before, after, activityId);
                    }
                    if (deleteBatches.Any() && batchIds.Any())
                    {
                        var before = string.Join(",", deleteBatches);
                        OpertionLogs(OpertionType.EditDelete, before, "", activityId);
                    }
                    if (addBatches.Any())
                    {
                        var after = string.Join(",", addBatches);
                        OpertionLogs(OpertionType.EditAdd, "", after, activityId);
                    }

                    #endregion

                    if (IsNeedUpdateAct)
                    {
                        DalVipCard.UpdateVipCardModel(activityName, activityId, dbHelper);
                    }
                    if (batchIds.Any())
                    {
                        var uDetail1 = DalVipCard.SetVipCardModelDetailStatus(cardId, batchIds, dbHelper);

                        var list = details.Select(r =>
                        {
                            r.ClientName = clientName;
                            r.ClientId   = clientId;

                            return(r);
                        }).ToList();
                        var uDetails2 = DalVipCard.UpdateVipCardModelDetails(cardId, list, dbHelper);
                    }
                }

                catch (Exception ex)
                {
                    result = false;
                    logger.Error(ex.Message, ex);
                }
            }
            return(result);
        }