예제 #1
0
        public FactorySpecificationCommentDTO PostComment(int userID, object dtoItems, out Notification notification)
        {
            notification      = new Notification();
            notification.Type = NotificationType.Success;

            FactorySpecificationCommentDTO dtoItem = ((Newtonsoft.Json.Linq.JObject)dtoItems).ToObject <FactorySpecificationCommentDTO>();

            try
            {
                using (var context = CreateContext())
                {
                    FactorySpecificationComment dbItem = new FactorySpecificationComment();

                    context.FactorySpecificationComment.Add(dbItem);

                    converter.DTO2DB_FactorySpecificationComment(dtoItem, ref dbItem);

                    dbItem.UpdatedBy   = userID;
                    dbItem.UpdatedDate = DateTime.Now;

                    context.SaveChanges();

                    dtoItem = converter.DB2DTO_FactorySpecificationComment(context.ClientSpecificationMng_FactoryMngFactoryComment_View.FirstOrDefault(o => o.FactorySpecificationCommentID == dbItem.FactorySpecificationCommentID));

                    int subDays = DateTime.Now.Subtract(dtoItem.UpdatedDate.ConvertStringToDateTime().Value).Days;
                    dtoItem.CanDelete = (userID == dtoItem.UpdatedBy && subDays <= 1);
                }
            }
            catch (Exception ex)
            {
                notification.Type    = NotificationType.Error;
                notification.Message = ex.Message;

                return(null);
            }

            return(dtoItem);
        }
예제 #2
0
 public void DTO2DB_FactorySpecificationComment(FactorySpecificationCommentDTO dtoItem, ref FactorySpecificationComment dbItem)
 {
     Mapper.Map <FactorySpecificationCommentDTO, FactorySpecificationComment>(dtoItem, dbItem);
 }