예제 #1
0
        // Add new key raw material
        public List <DTO.FactorySpecificationComment> UpdateComment(int userId, object dtoItem, out Library.DTO.Notification notification)
        {
            List <DTO.FactorySpecificationComment> dtoCommnetList = ((Newtonsoft.Json.Linq.JArray)dtoItem).ToObject <List <DTO.FactorySpecificationComment> >();

            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            List <DTO.FactorySpecificationComment> DTOCommentList = new List <DTO.FactorySpecificationComment>();

            try
            {
                using (FactorySpecificationMngEntities context = CreateContext())
                {
                    var dbItemList = context.FactorySpecificationComment.Select(o => o).ToList();

                    //Delete orphan
                    foreach (var item in dbItemList.ToArray())
                    {
                        if (!dtoCommnetList.Select(o => o.FactorySpecificationCommentID).Contains(item.FactorySpecificationCommentID))
                        {
                            if (item.UpdatedBy == userId)
                            {
                                context.FactorySpecificationComment.Remove(item);
                            }
                            else
                            {
                                throw new Exception("Unable to delete other user comment");
                            }
                        }
                    }

                    //Map child row
                    foreach (var item in dtoCommnetList)
                    {
                        FactorySpecificationComment dbComment;
                        if (item.FactorySpecificationCommentID <= 0)
                        {
                            dbComment = new FactorySpecificationComment();
                            context.FactorySpecificationComment.Add(dbComment);
                            AutoMapper.Mapper.Map <DTO.FactorySpecificationComment, FactorySpecificationComment>(item, dbComment);

                            dbComment.UpdatedDate = DateTime.Now;
                            dbComment.UpdatedBy   = userId;
                        }
                    }

                    context.SaveChanges();
                }
                DTOCommentList = GetCommentList(userId);
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(DTOCommentList);
        }
예제 #2
0
        public override bool DeleteData(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (FactorySpecificationMngEntities context = CreateContext())
                {
                    FactorySpecification dbItem = context.FactorySpecification.FirstOrDefault(o => o.FactorySpecificationID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Sub Supplier not found!";
                        return(false);
                    }
                    else
                    {
                        context.FactorySpecification.Remove(dbItem);
                        context.SaveChanges();

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                notification.DetailMessage.Add(ex.Message);
                if (ex.GetBaseException() != null)
                {
                    notification.DetailMessage.Add(ex.GetBaseException().Message);
                }
                return(false);
            }
        }
예제 #3
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            DTO.FactorySpecification dtoFactorySpecification = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.FactorySpecification>();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (FactorySpecificationMngEntities context = CreateContext())
                {
                    FactorySpecification dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new FactorySpecification();
                        context.FactorySpecification.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.FactorySpecification.FirstOrDefault(o => o.FactorySpecificationID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Factory Raw Material not found!";
                        return(false);
                    }
                    else
                    {
                        // check concurrency
                        //if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoFactorySpecification.ConcurrencyFlag_String)))
                        //{
                        //    throw new Exception(Library.Helper.TEXT_CONCURRENCY_CONFLICT);
                        //}

                        // processing logo image
                        if (dtoFactorySpecification.FactoryFileLocation_HasChange)
                        {
                            dtoFactorySpecification.FactorySpecificationFileUD = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoFactorySpecification.NewFile, dtoFactorySpecification.FactorySpecificationFileUD);
                        }

                        //convert dto to db
                        converter.DTO2BD(dtoFactorySpecification, ref dbItem);

                        context.FactorySpecificationComment.Local.Where(o => o.FactorySpecification == null).ToList().ForEach(o => context.FactorySpecificationComment.Remove(o));

                        dbItem.FactorySpecificationRemark = dtoFactorySpecification.FactorySpecificationRemark;

                        dbItem.FactorySpecificationUpdatedDate = DateTime.Now;
                        dbItem.FactorySpecificationUpdatedBy   = userId;

                        context.SaveChanges();

                        dtoItem = GetData(userId, dbItem.FactorySpecificationID, out notification).Data;

                        return(true);
                    }
                }
            }

            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }
        }