Exemple #1
0
        public List <CashBookCostItemDetailData> UpdateCostItemDetailData(int userId, object dtoItem, out Notification notification)
        {
            notification = new Notification()
            {
                Type = NotificationType.Success
            };

            CashBookCostItemDetailData        dataItem     = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <CashBookCostItemDetailData>();
            List <CashBookCostItemDetailData> costItemData = new List <CashBookCostItemDetailData>();

            try
            {
                using (var context = CreateContext())
                {
                    CashBookCostItemDetail dbItem;

                    if (dataItem.CashBookCostItemDetailID > 0)
                    {
                        dbItem = context.CashBookCostItemDetail.FirstOrDefault(o => o.CashBookCostItemDetailID == dataItem.CashBookCostItemDetailID);

                        if (dbItem == null)
                        {
                            notification.Type    = NotificationType.Error;
                            notification.Message = "Can not found data!";

                            return(costItemData);
                        }
                    }
                    else
                    {
                        dbItem = new CashBookCostItemDetail();
                        context.CashBookCostItemDetail.Add(dbItem);
                    }

                    converter.DTO2DB_CashBookCostItemDetail(dataItem, ref dbItem);
                    dbItem.UpdatedBy   = userId;
                    dbItem.UpdatedDate = DateTime.Now;

                    context.SaveChanges();

                    costItemData = converter.DB2DTO_CashBookCostItemDetail(context.CashBookMng_CashBookCostItemDetail_View.ToList());
                }

                return(costItemData);
            }
            catch (Exception ex)
            {
                notification.Type    = NotificationType.Error;
                notification.Message = ex.Message;
                return(costItemData);
            }
        }
Exemple #2
0
        public bool DeleteCostItemDetailData(int id, out Notification notification)
        {
            notification = new Notification()
            {
                Type = NotificationType.Success
            };

            try
            {
                using (var context = CreateContext())
                {
                    CashBookCostItemDetail dbItem = context.CashBookCostItemDetail.FirstOrDefault(o => o.CashBookCostItemDetailID == id);

                    if (dbItem == null)
                    {
                        notification.Type    = NotificationType.Error;
                        notification.Message = "Can not found data!";

                        return(false);
                    }

                    // set null for all item using it.
                    var dbItem2 = context.CashBook.Where(o => o.CashBookCostItemDetailID == dbItem.CashBookCostItemDetailID);
                    foreach (var item in dbItem2)
                    {
                        item.CashBookCostItemDetailID = null;
                    }

                    context.CashBookCostItemDetail.Remove(dbItem);
                    context.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                notification.Type    = NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }
        }
Exemple #3
0
 public void DTO2DB_CashBookCostItemDetail(DTO.CashBookCostItemDetailData dataItem, ref CashBookCostItemDetail dbItem)
 {
     AutoMapper.Mapper.Map <DTO.CashBookCostItemDetailData, CashBookCostItemDetail>(dataItem, dbItem);
 }