コード例 #1
0
        public ActionResult Create(BranchOfficeModel model)
        {
            if (ModelState.IsValid)
            {
                var office = new BranchOffice
                {
                    BranchName = model.BranchName,
                    Abbreviation = model.Abbreviation,
                    CreatedOn = DateTime.UtcNow,
                    UpdatedOn = DateTime.UtcNow,
                    CurrentPublishingStatus = PublishingStatus.Active // by default the client status is active
                };

                if (!string.IsNullOrEmpty(model.Address.Address1) ||
                    !string.IsNullOrEmpty(model.Address.City) || !string.IsNullOrEmpty(model.Address.PhoneNumber) ||
                    !string.IsNullOrEmpty(model.Address.FaxNumber) || model.Address.CountryId.HasValue || model.Address.StateProvinceId.HasValue)
                {
                    office.Address = model.Address.ToEntity();
                    office.Address.CreatedOn = office.Address.UpdatedOn = DateTime.UtcNow;
                }

                // we need to add this client
                dataService.Insert(office);

                // return notification message
                SuccessNotification(localizationService.GetResource("BranchOffice.Added"));
                return RedirectToAction(SystemRouteNames.Index);
            }

            //If we got this far, something failed, redisplay form
            PrepareAddEditModel(model);

            return View(model);
        }
コード例 #2
0
        public ActionResult Create()
        {
            var model = new BranchOfficeModel();
            PrepareAddEditModel(model);

            return View(model);
        }
コード例 #3
0
        private BranchOfficeModel PrepareBranchOfficeModel(BranchOffice office)
        {
            Guard.IsNotNull(office, "office");

            var model = new BranchOfficeModel()
                {
                    RowId = office.RowId,
                    Abbreviation = office.Abbreviation,
                    BranchName = office.BranchName,
                    Address = office.Address.ToModel()
                };

            PrepareAuditHistoryModel(model, office);

            return model;
        }
コード例 #4
0
        private void PrepareAddEditModel(BranchOfficeModel model)
        {
            Guard.IsNotNull(model, "model");

            // add countries
            var countryId = model.Address.CountryId.HasValue ? model.Address.CountryId.Value : Guid.Empty;

            countryService.GetAll()
            .ForEach(c =>
            {
                model.Address.AvailableCountries.Add(new SelectListItem() { Text = c.Name, Value = c.RowId.ToString(), Selected = (c.RowId == countryId) });
            });

            if (!countryId.IsEmpty())
            {
                var states = stateprovinceService.GetByCountryId(countryId);
                if (states.Count > 0)
                {
                    states.ForEach(s =>
                    {
                        model.Address.AvailableStates.Add(new SelectListItem()
                        {
                            Text = s.GetLocalized(x => x.Name),
                            Value = s.RowId.ToString(),
                            Selected = (model.Address.StateProvinceId.HasValue ? s.RowId == model.Address.StateProvinceId : false)
                        });
                    });
                }
            }
        }
コード例 #5
0
        public ActionResult Edit(BranchOfficeModel model)
        {
            if (ModelState.IsValid)
            {
                var office = dataService.GetById(model.RowId);

                if (office == null)
                    return RedirectToAction(SystemRouteNames.Index);

                // update the properties
                model.Address.ToEntity( office.Address );
                office.UpdatedOn = office.Address.UpdatedOn = DateTime.UtcNow;

                // we need to update this client
                dataService.Update(office);

                // return notification message
                SuccessNotification(localizationService.GetResource("BranchOffice.Updated"));
                return RedirectToAction(SystemRouteNames.Index);
            }

            var errors = ModelState.GetModelErrors();
            //If we got this far, something failed, redisplay form
            PrepareAddEditModel(model);

            return View(model);
        }
コード例 #6
0
        // branch office
        public static BranchOfficeModel ToModel(this BranchOffice entity)
        {
            if (entity == null)
                return null;

            var model = new BranchOfficeModel()
            {
                RowId = entity.RowId,
                BranchName = entity.BranchName,
                Abbreviation = entity.Abbreviation,
                Address = entity.Address.ToModel()
            };

            return model;
        }