Beispiel #1
0
 public static void CopyNewData(this Customer customerOld, CustomerCreateEditModel customerNew)
 {
     customerOld.ContactInfo = customerNew.ContactInfo;
     customerOld.Name        = customerNew.Name;
     customerOld.Status      = customerNew.Status;
     customerOld.Notes       = customerNew.Notes.Split(Environment.NewLine).Where(text => !string.IsNullOrWhiteSpace(text)).Select(row => new Note {
         Text = row
     }).ToList();
 }
Beispiel #2
0
        public async Task <IActionResult> Edit([FromForm] CustomerCreateEditModel editedCustomer)
        {
            var da       = this._dataAccess.GetCustomerDataAccess();
            var customer = await da.Get(editedCustomer.Id).ConfigureAwait(false);

            customer.CopyNewData(editedCustomer);
            await da.Upsert(customer);

            return(this.RedirectToAction(nameof(this.Index)));
        }
Beispiel #3
0
        public async Task <IActionResult> Create([FromForm] CustomerCreateEditModel newCustomer)
        {
            var customer = newCustomer.GetCustomer();

            customer.CreatedTimestamp = DateTimeOffset.UtcNow;

            var da = this._dataAccess.GetCustomerDataAccess();
            await da.Upsert(customer);

            return(this.RedirectToAction(nameof(this.Index)));
        }
Beispiel #4
0
        public static CustomerCreateEditModel GetCustomerEditModel(this Customer customer)
        {
            var customerEdit = new CustomerCreateEditModel
            {
                Id          = customer.Id,
                ContactInfo = customer.ContactInfo,
                Status      = customer.Status,
                Name        = customer.Name,
                Notes       = customer.Notes != null?string.Join(Environment.NewLine, customer.Notes.Select(note => note.Text)) : string.Empty
            };

            return(customerEdit);
        }
Beispiel #5
0
        public static Customer GetCustomer(this CustomerCreateEditModel customerEdit)
        {
            var customer = new Customer
            {
                Id          = customerEdit.Id,
                ContactInfo = customerEdit.ContactInfo,
                Name        = customerEdit.Name,
                Status      = customerEdit.Status,
                Notes       = customerEdit.Notes?.Split(Environment.NewLine).Where(text => !string.IsNullOrWhiteSpace(text)).Select(row => new Note {
                    Text = row
                }).ToList()
            };

            return(customer);
        }