Esempio n. 1
0
 private ManagerViewModel RefreshManager()
 {
     ManagerViewModel model = new ManagerViewModel();
     model.FieldId = "managerName";
     model.Regions = _bdmSvc.GetAllRegions(AppConstants.SITE_CODE);
     model.Managers = _bdmSvc.GetViewOfAllEntities(AppConstants.SITE_CODE).Where(m => m.EntityTypeCode == EntityTypes.MGR.ToString()).ToList();
     return model;
 }
Esempio n. 2
0
 public ManagerViewModel GetManagerById(decimal managerId)
 {
     ManagerViewModel mod = new ManagerViewModel();
     try
     {
         //mod.Manager = _bdmSvc.GetEntityById(AppConstants.SITE_CODE, managerId);
         //if (mod.Manager.Addresses.Count > 0)
         //    mod.Address = mod.Manager.Addresses[0];
         //if (mod.Manager.Contacts.Count > 0)
         //    mod.Contact = mod.Manager.Contacts[0];
     }
     catch (Exception ex)
     {
         mod.TranslateException(ex);
     }
     return mod;
 }
Esempio n. 3
0
        public ManagerViewModel ModifyManager(ManagerViewModel model)
        {
            try
            {
                DBOperations op = model.IsActive ? DBOperations.Update : DBOperations.Delete;
                model.Manager.SiteCode = AppConstants.SITE_CODE;
                if (model.IsActive)
                {
                    model.IsValid = model.Validate();
                    if (model.IsValid)
                    {
                        model.Address = base.TranslateNames(model.Address);

                        if (model.Manager.Addresses.Count > 0)
                            model.Manager.Addresses[0] = model.Address.Translate(model.Manager.Addresses[0]);

                        if (model.Manager.Contacts.Count > 0)
                            model.Manager.Contacts[0] = model.Contact.Translate(model.Manager.Contacts[0]);

                        _bdmSvc.ModifyEntity(model.Manager);
                    }
                }
                else
                {
                    model.Manager.IsActive = false;
                    _bdmSvc.ModifyEntity(model.Manager);
                }

                model = RefreshManager();
                model.Message = op == DBOperations.Update ? string.Format(AppConstants.CRUD_UPDATE, "Manager") : string.Format(AppConstants.CRUD_DELETE, "Manager");
            }
            catch (Exception ex)
            {
                model.TranslateException(ex);
                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;
        }
Esempio n. 4
0
        public ManagerViewModel AddManager(ManagerViewModel model)
        {
            try
            {
                model.IsValid = model.Validate();
                if (model.IsValid)
                {
                    model.Manager.SiteCode = AppConstants.SITE_CODE;

                    model.Address = base.TranslateNames(model.Address);

                    model.Manager.Addresses.Add(model.Address);
                    model.Manager.Contacts.Add(model.Contact);
                    _bdmSvc.AddEntity(model.Manager);

                    model = RefreshManager();
                    model.Message = string.Format(AppConstants.CRUD_CREATE, "Manager");
                }
            }
            catch (Exception ex)
            {
                model.TranslateException(ex);
            }

            return model;
        }