Beispiel #1
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);
        }
Beispiel #2
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;
        }
Beispiel #3
0
        /// <summary>
        /// Updates the client
        /// </summary>
        /// <param name="client">client</param>
        public virtual void Update(Client client)
        {
            Guard.IsNotNull(client, "client");

            // add audit history
            client.AuditHistory.Add
             (
                userActivityService.InsertActivity(SystemActivityLogTypeNames.Update,
                    client.ToString(), StateKeyManager.CLIENT_ACTIVITY_COMMENT, client.ClientName)
             );

            this.clientRepository.Update(client);

            this.cacheManager.RemoveByPattern(CLIENTS_PATTERN_KEY);

            //event notification
            this.eventPublisher.EntityUpdated(client);
        }