コード例 #1
0
        public override bool Approve(int id, ref DTO.ShippingInstructionMng.ShippingInstruction dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };

            try
            {
                using (ShippingInstructionMngEntities context = CreateContext())
                {
                    ShippingInstruction dbItem = context.ShippingInstruction.FirstOrDefault(o => o.ShippingInstructionID == id);
                    if (dbItem != null)
                    {
                        dbItem.IsConfirmed   = true;
                        dbItem.ConfirmedBy   = dtoItem.UpdatedBy;
                        dbItem.ConfirmedDate = DateTime.Now;
                        context.SaveChanges();

                        dtoItem = GetData(id, out notification).Data;
                        return(true);
                    }
                    else
                    {
                        throw new Exception("Shipping instruction not found!");
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }
        }
コード例 #2
0
        public override bool UpdateData(int id, ref DTO.ShippingInstructionMng.ShippingInstruction dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (ShippingInstructionMngEntities context = CreateContext())
                {
                    ShippingInstruction dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new ShippingInstruction();
                        context.ShippingInstruction.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.ShippingInstruction.FirstOrDefault(o => o.ShippingInstructionID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Shipping instruction not found!";
                        return(false);
                    }
                    else
                    {
                        // check concurrency
                        if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoItem.ConcurrencyFlag_String)))
                        {
                            throw new Exception(DALBase.Helper.TEXT_CONCURRENCY_CONFLICT);
                        }

                        // reset default
                        if (dtoItem.IsDefault.HasValue && dtoItem.IsDefault.Value)
                        {
                            int        ClientID       = dtoItem.ClientID.Value;
                            List <int> InstructionIDs = context.ShippingInstructionMng_ShippingInstruction_View.Where(o => o.ClientID == ClientID).Select(o => o.ShippingInstructionID).ToList();
                            context.ShippingInstruction.Where(o => InstructionIDs.Contains(o.ShippingInstructionID)).ToList().ForEach(o => o.IsDefault = null);
                        }

                        converter.DTO2DB(dtoItem, ref dbItem);
                        context.SaveChanges();

                        dtoItem = GetData(dbItem.ShippingInstructionID, out notification).Data;
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification = new Library.DTO.Notification()
                {
                    Message = ex.Message, Type = Library.DTO.NotificationType.Error
                };
                return(false);
            }
        }
コード例 #3
0
        public override bool DeleteData(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (ShippingInstructionMngEntities context = CreateContext())
                {
                    ShippingInstruction dbItem = context.ShippingInstruction.FirstOrDefault(o => o.ShippingInstructionID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Shipping instruction not found!";
                        return(false);
                    }
                    else
                    {
                        if (dbItem.IsConfirmed.HasValue && dbItem.IsConfirmed.Value)
                        {
                            throw new Exception("The shipping instruction has been confirmed and can not be deleted");
                        }

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

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification = new Library.DTO.Notification()
                {
                    Message = ex.Message
                };
                return(false);
            }
        }
コード例 #4
0
 public void DTO2DB(DTO.ShippingInstructionMng.ShippingInstruction dtoItem, ref ShippingInstruction dbItem)
 {
     // map fields
     AutoMapper.Mapper.Map <DTO.ShippingInstructionMng.ShippingInstruction, ShippingInstruction>(dtoItem, dbItem);
     dbItem.UpdatedDate = DateTime.Now;
 }