Exemple #1
0
        public SaveResult <MenuEntryModel> Save(MenuDTO menuDTO, DateTime dateStamp)
        {
            ModelValidationResult validationResult = menuValidator.Validate(menuDTO);
            bool           success = false;
            MenuEntryModel model   = null;

            if (!validationResult.IsValid)
            {
                return(new SaveResult <MenuEntryModel>
                {
                    Success = success,
                    Message = validationResult.IsValid ? "Data successfully created." : "Validation error occured.",
                    Model = model,
                    ValidationResult = validationResult
                });
            }
            tblM_Menu menu = AddMenu(menuDTO, dateStamp);

            Db.SaveChanges();

            success = true;
            model   = menuEntryDataProvider.Get(menu.Menu_PK);

            return(new SaveResult <MenuEntryModel>
            {
                Success = success,
                Message = validationResult.IsValid ? "Data successfully created." : "Validation error occured.",
                Model = model,
                ValidationResult = validationResult
            });
        }
Exemple #2
0
 public void UpdateMenu(MenuDTO menuDTO, DateTime dateStamp)
 {
     if (menuDTO == null)
     {
         throw new ArgumentNullException("Menu model is null.");
     }
     tblM_Menu menu = menuFactory.CreateFromDbAndUpdateFromDTO(menuDTO, dateStamp);
 }
Exemple #3
0
        public tblM_Menu AddMenu(MenuDTO menuDTO, DateTime dateStamp)
        {
            if (menuDTO == null)
            {
                throw new ArgumentNullException("Menu model is null.");
            }
            tblM_Menu menu = menuFactory.CreateFromDTO(menuDTO, dateStamp);

            return(Db.tblM_Menu.Add(menu));
        }
Exemple #4
0
        public tblM_Menu CreateFromDTO(MenuDTO menuDTO, DateTime dateStamp)
        {
            if (menuDTO == null)
            {
                throw new ArgumentNullException("Menu model is null.");
            }
            menuDTO.Status_FK   = (int)RecordStatus.Active;
            menuDTO.CreatedBy   = User.Username;
            menuDTO.CreatedDate = dateStamp;
            menuDTO.UpdatedBy   = User.Username;
            menuDTO.UpdatedDate = dateStamp;
            tblM_Menu menu = menuDTO.ToObject <tblM_Menu>();

            return(menu);
        }
Exemple #5
0
        public tblM_Menu CreateFromDbAndUpdateFromDTO(MenuDTO menuDTO, DateTime dateStamp)
        {
            tblM_Menu menu;

            if (menuDTO == null)
            {
                throw new ArgumentNullException("Menu model is null.");
            }
            menu = Db.tblM_Menu.Find(menuDTO.Menu_PK);
            if (menu == null)
            {
                throw new KairosException($"Record with key '{menuDTO.Menu_PK}' is not found.");
            }

            menu.UpdateValueFrom(menuDTO, "Menu_PK", "Status_FK");
            menuDTO.CreatedBy   = menu.CreatedBy;
            menuDTO.CreatedDate = menu.CreatedDate;
            menu.UpdatedBy      = menuDTO.UpdatedBy = User.Username;
            menu.UpdatedDate    = menuDTO.UpdatedDate = dateStamp;

            return(menu);
        }
Exemple #6
0
        public MenuDTO GetByCode(string code)
        {
            MenuDTO record = GetQuery().FirstOrDefault(menu => menu.Code == code);

            return(record);
        }
Exemple #7
0
        public MenuDTO GetByPrimaryKey(int primaryKey)
        {
            MenuDTO record = GetQuery().FirstOrDefault(menu => menu.Menu_PK == primaryKey);

            return(record);
        }