예제 #1
0
        public AreaViewModel AddArea(AreaViewModel model)
        {
            try
            {
                model.IsValid = model.Validate();
                if (model.IsValid)
                {
                    if (_bdmSvc.AreaCodeExists(AppConstants.SITE_CODE, model.Area.AreaCode))
                    {
                        model.FieldId = "areaCode";
                        model.Message = string.Format(AppConstants.VALIDATION_ALREADY_EXISTS, "Area Code");
                        model.IsValid = false;
                    }

                    if (model.IsValid)
                    {
                        model.Area.SiteCode = AppConstants.SITE_CODE;
                        _bdmSvc.AddArea(model.Area);

                        model.FieldId = "areaCode";
                        model.Area = new AreaDE();
                        model.Regions = _bdmSvc.GetAllRegions(AppConstants.SITE_CODE);
                        model.Areas = _bdmSvc.GetViewOfAllAreas(AppConstants.SITE_CODE);
                        model.Message = string.Format(AppConstants.CRUD_CREATE, model.ViewName);
                    }
                }
            }
            catch (Exception ex)
            {
                model.IsValid = false;
                model.Message = ex.Message;
            }

            return model;
        }
예제 #2
0
        public AreaViewModel ModifyArea(AreaDE mod)
        {
            AreaViewModel model = new AreaViewModel();

            try
            {
                DBOperations op = mod.IsActive ? DBOperations.Update : DBOperations.Delete;
                mod.SiteCode = AppConstants.SITE_CODE;
                model.Area = mod;
                model.IsValid = model.Validate();
                if (model.IsValid)
                {
                    _bdmSvc.ModifyArea(mod);

                    model.FieldId = "areaCode";
                    model.Area = new AreaDE();
                    model.Regions = _bdmSvc.GetAllRegions(AppConstants.SITE_CODE);
                    model.Areas = _bdmSvc.GetViewOfAllAreas(AppConstants.SITE_CODE);
                    model.Message = op == DBOperations.Update ? string.Format(AppConstants.CRUD_UPDATE, model.ViewName) : string.Format(AppConstants.CRUD_DELETE, "Area");
                }
            }
            catch (Exception ex)
            {
                model.IsValid = false;
                model.Message = ex.Message;
                if (ex.Message.Contains("Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=472540 for information on understanding and handling optimistic concurrency exceptions."))
                    model.Message = "Unable to modify Region Code";
            }
            return model;
        }
예제 #3
0
        public AreaViewModel GetAllAreas()
        {
            var mod = new AreaViewModel();
            mod.IsValid = true;
            try
            {
                mod.Regions = _bdmSvc.GetAllRegions(AppConstants.SITE_CODE);
                mod.Areas = _bdmSvc.GetViewOfAllAreas(AppConstants.SITE_CODE);
            }
            catch (Exception ex)
            {
                mod.IsValid = false;
                mod.Message = ex.Message;
            }

            return mod;
        }