Esempio n. 1
0
        private ClientModel PrepareClientModel(Client client)
        {
            Guard.IsNotNull(client, "client");

            var model = new ClientModel()
                {
                    RowId = client.RowId,
                    Email =  client.Email,
                    ClientName = client.ClientName,
                    Address = client.Address.ToModel()
                };

            PrepareOfficeAssociationModel(model, client, officeService, cacheManager);
            PrepareAuditHistoryModel(model, client);

            return model;
        }
Esempio n. 2
0
        private void PrepareAddEditModel(ClientModel 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)
                        });
                    });
                }
            }

            model.AvailableOffices = base.PrepareSelectList(officeService, cacheManager);
        }
Esempio n. 3
0
        public ActionResult Edit(ClientModel model)
        {
            if (ModelState.IsValid)
            {
                var client = clientService.GetById(model.RowId);

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

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

                // add the associated branches to this client
                var associatedOffices = model.OfficeId.ToList<Guid>();
                attributeService.SaveAttribute<List<Guid>>(client, SystemAttributeNames.AssociatedBrancOffices,
                    associatedOffices);

                client.AuditHistory.Add
                (
                    userActivityService.InsertActivity(SystemActivityLogTypeNames.EntityOfficeAssociation,
                        PrepareOfficeAssociationModel(associatedOffices, officeService, cacheManager), StateKeyManager.CLIENT_ACTIVITY_COMMENT, client.ClientName)
                );
                // we need to update this client
                clientService.Update(client);

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

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

            return View(model);
        }
Esempio n. 4
0
        public ActionResult Create(ClientModel model)
        {
            if (ModelState.IsValid)
            {
                var client = new Client
                {
                    ClientName = model.ClientName,
                    Email = model.Email,
                    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)
                {
                    client.Address = model.Address.ToEntity();
                    client.Address.CreatedOn = client.Address.UpdatedOn = DateTime.UtcNow;
                }

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

                // add the associated branches to this client
                var associatedOffices = model.OfficeId.ToList<Guid>();
                attributeService.SaveAttribute<List<Guid>>(client, SystemAttributeNames.AssociatedBrancOffices,
                    associatedOffices);

                client.AuditHistory.Add
                (
                    userActivityService.InsertActivity(SystemActivityLogTypeNames.EntityOfficeAssociation,
                        PrepareOfficeAssociationModel(associatedOffices, officeService, cacheManager), StateKeyManager.CLIENT_ACTIVITY_COMMENT, client.ClientName)
                );
                clientService.Update(client);

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

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

            return View(model);
        }
Esempio n. 5
0
        public ActionResult Create()
        {
            var model = new ClientModel();
            PrepareAddEditModel(model);

            return View(model);
        }
Esempio n. 6
0
        // clients
        public static ClientModel ToModel(this Client entity)
        {
            if (entity == null)
                return null;

            var model = new ClientModel()
            {
                RowId = entity.RowId,
                ClientName = entity.ClientName,
                Email = entity.Email,
                Address = entity.Address.ToModel()
            };

            return model;
        }