コード例 #1
0
        public MenuHistory Update(MenuHistoryDTO dto)
        {
            using (var transac = new TransactionScope())
            {
                var userId = 1;
                var date   = DateTime.UtcNow;

                var exist = Manager.Query.Value.Get().FirstOrDefault(s => s.MenuHistoryId == dto.MenuHistoryId);
                if (exist == null)
                {
                    throw new Exception("Your menu doesn't exist");
                }
                else
                {
                    exist.MenuCode    = dto.MenuCode;
                    exist.MenuType    = dto.MenuType;
                    exist.Name        = dto.Name;
                    exist.Address     = dto.Address;
                    exist.Price       = dto.Price;
                    exist.UpdatedBy   = userId;
                    exist.UpdatedDate = date;
                    Manager.Database.SaveChanges();
                }

                transac.Complete();

                return(exist);
            }
        }
コード例 #2
0
        public MenuHistory Save(MenuHistoryDTO dto, long userId)
        {
            using (var transac = new TransactionScope())
            {
                var date = DateTime.UtcNow;

                var newEntity = new MenuHistory
                {
                    MenuCode    = dto.MenuCode,
                    MenuType    = dto.MenuType,
                    Name        = dto.Name,
                    Address     = dto.Address,
                    CreatedBy   = (int)userId,
                    CreatedDate = date,
                    UpdatedBy   = (int)userId,
                    UpdatedDate = date,
                    Price       = dto.Price
                };

                Manager.Database.MenuHistories.Add(newEntity);
                Manager.Database.SaveChanges();
                transac.Complete();

                return(newEntity);
            }
        }