예제 #1
0
        public void CanUpdateAggregateCustomerRecords()
        {
            try
            {
                var            customer   = _CustomerService.GetCustomerByID("1");
                CustomerRecord nameRecord = customer.CustomerDataRecords.Where(r => r.Property.Name == "Name").FirstOrDefault();
                Assert.AreEqual(nameRecord.Property.Name, "Name");
                Assert.AreEqual(nameRecord.Type.Name, "Customer");
                Assert.AreEqual(nameRecord.Value, "Hadar");
                CustomerRecord ageRecord = customer.CustomerDataRecords.Where(r => r.Property.Name == "Age").FirstOrDefault();
                Assert.AreEqual(ageRecord.Property.Name, "Age");
                Assert.AreEqual(ageRecord.Type.Name, "Customer");
                Assert.AreEqual(ageRecord.Value, "47");
                nameRecord.Value = "UpdatedName";
                ageRecord.Value  = "42";
                _CustomerService.UpdateCustomerRecords(customer);

                AggregateCustomer retreivedCreatedCustomer = _CustomerService.GetCustomerByID("1");
                CustomerRecord    updatedNameRecord        = customer.CustomerDataRecords.Where(r => r.Property.Name == "Name").FirstOrDefault();
                Assert.AreEqual(updatedNameRecord.Property.Name, "Name");
                Assert.AreEqual(updatedNameRecord.Type.Name, "Customer");
                Assert.AreEqual(updatedNameRecord.Value, "UpdatedName");
                CustomerRecord updatedAgeRecord = customer.CustomerDataRecords.Where(r => r.Property.Name == "Age").FirstOrDefault();
                Assert.AreEqual(updatedAgeRecord.Property.Name, "Age");
                Assert.AreEqual(updatedAgeRecord.Type.Name, "Customer");
                Assert.AreEqual(updatedAgeRecord.Value, "42");
            }
            catch (Exception ex)
            {
                Assert.Fail("Expected no exception, but got: " + ex.Message);
            }
        }
예제 #2
0
        public AggregateCustomer CreateCustomer(AggregateCustomer aggregateCustomer)
        {
            try
            {
                //var simulatedCust = new AggregateCustomer();
                //simulatedCust.CustomerId = aggregateCustomer.CustomerId;
                //simulatedCust.CustomerDataRecords = new List<CustomerRecord>();
                //simulatedCust.CustomerDataRecords.Add(new CustomerRecord() { RecordId = Guid.NewGuid(), CustomerId= simulatedCust.CustomerId, Value= "NewlyCreatedCustomerValue", TypeId="1", PropertyId="1" });
                //_CustomerRecords.Add(simulatedCust.CustomerDataRecords[0]);
                //_uow.Save();

                foreach (var dataRecord in aggregateCustomer.CustomerDataRecords)
                {
                    _CustomerRecords.Add(dataRecord);
                    _uow.Save();
                }
                AggregateCustomer retrievedCust = GetCustomerByID(aggregateCustomer.CustomerId);

                return(retrievedCust);
            }
            catch (Exception ex)
            {
                return(null);

                throw new Exception("Failure creating Customer", ex);
            }
        }
예제 #3
0
        public void CreatingNewCustomerWithSameIdThrows()
        {
            AggregateCustomer customer = new AggregateCustomer();

            customer.CustomerId             = Guid.NewGuid().ToString();
            customer.CustomerDataRecords[0] = new CustomerRecord
            {
                CustomerId = "1",
                TypeId     = "1",
                PropertyId = "1",
                Value      = "Hadar",
                Type       = new Backend.EntityFramework.Type {
                    TypeId = "1", Name = "Customer"
                },
                Property = new Backend.EntityFramework.Property {
                    PropertyId = "1", Name = "Name"
                },
                RecordId = Guid.NewGuid()
            };
            customer.CustomerDataRecords[1] = new CustomerRecord
            {
                CustomerId = "1",
                TypeId     = "1",
                PropertyId = "2",
                Value      = "47",
                Type       = new Backend.EntityFramework.Type {
                    TypeId = "1", Name = "Customer"
                },
                Property = new Backend.EntityFramework.Property {
                    PropertyId = "2", Name = "Age"
                },
                RecordId = Guid.NewGuid()
            };
            _CustomerService.CreateCustomer(customer);
        }
 private void EnsureProperties(AggregateCustomer retrievedCustomerRecord)
 {
     foreach (var item in retrievedCustomerRecord.CustomerDataRecords)
     {
         if (item.Property == null)
         {
             item.Property = _propertyService.GetPropertyByID(item.PropertyId);
         }
     }
 }
        // GET: Maintenance/Delete/5
        public async Task <ActionResult> Delete(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AggregateCustomer customerRecord = _customerService.GetCustomerByID(id);

            if (customerRecord == null)
            {
                return(HttpNotFound());
            }
            return(View(customerRecord));
        }
예제 #6
0
 public AggregateCustomer GetCustomerByID(string id)
 {
     try
     {
         var customerRecordsMatchingId = _CustomerRecords.GetAll().Where(c => c.CustomerId == id);
         AggregateCustomer ac          = new AggregateCustomer();
         ac.CustomerDataRecords = new List <CustomerRecord>();
         ac.CustomerDataRecords.AddRange(customerRecordsMatchingId);
         return(ac);
     }
     catch (Exception ex)
     {
         throw new Exception("Failure getting Customer", ex);
     }
 }
        public async Task <ActionResult> DeleteConfirmed(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AggregateCustomer customerRecord = _customerService.GetCustomerByID(id);

            if (customerRecord == null)
            {
                return(HttpNotFound());
            }
            _customerService.DeleteCustomerByID(id);
            return(RedirectToAction("Index"));
        }
        // GET: Maintenance/Edit/5
        public async Task <ActionResult> Edit(string id)
        {
            if (id == null || id == String.Empty)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AggregateCustomer retrievedCustomerRecord = _customerService.GetCustomerByID(id);

            retrievedCustomerRecord.CustomerId = id;
            AggregateCustomerViewModel serializableCustomerReocrd = Mapper.Map <AggregateCustomer, AggregateCustomerViewModel>(retrievedCustomerRecord);

            var jsonCustomerRecord = AggregateCustomerViewModel.Serialize(serializableCustomerReocrd);

            return(View(serializableCustomerReocrd));
        }
예제 #9
0
        public IEnumerable <AggregateCustomer> GetAllCustomers()
        {
            var customerRecords     = _CustomerRecords.GetAll();
            var aggregatedCustomers = customerRecords.GroupBy(c => c.CustomerId);
            List <AggregateCustomer> customersToReturn = new List <AggregateCustomer>();

            foreach (var groupedCustomerRecords in aggregatedCustomers)
            {
                AggregateCustomer ac = new AggregateCustomer();
                ac.CustomerDataRecords = new List <CustomerRecord>();
                ac.CustomerDataRecords.AddRange(groupedCustomerRecords);
                customersToReturn.Add(ac);
            }
            return(customersToReturn);

            //return _CustomerRecords.GetAll();
        }
예제 #10
0
        public bool UpdateCustomerRecords(AggregateCustomer aggregateCustomer)
        {
            try
            {
                foreach (var dataRecord in aggregateCustomer.CustomerDataRecords)
                {
                    _CustomerRecords.Update(dataRecord);
                    _uow.Save();
                }

                return(true);
            }
            catch (Exception ex)
            {
                return(false);

                throw new Exception("Failure getting Customer", ex);
            }
        }
        public JsonResult EditPostedJson([JsonBinder] AggregateCustomerViewModel updatedCustomer)
        //public async Task<ActionResult> Edit(AggregateCustomer customerRecord)
        {
            var  editedCustomerId = ViewBag.CustomerId;
            bool editedCustomer   = false;

            if (ModelState.IsValid)
            {
                AggregateCustomer newRecord = new AggregateCustomer();
                newRecord.CustomerDataRecords = new List <CustomerRecord>();
                var retrievedCustomer = _customerService.GetCustomerByID(updatedCustomer.CustomerId);
                EnsureProperties(retrievedCustomer);
                for (int i = 0; i < updatedCustomer.CustomerDataRecords.Count; i++)
                {
                    var currentUpdatedProperty = updatedCustomer.CustomerDataRecords[i].Property.Name;
                    for (int j = 0; j < retrievedCustomer.CustomerDataRecords.Count; j++)
                    {
                        var currentRetreivedProperty = retrievedCustomer.CustomerDataRecords[j].Property.Name;
                        if (currentRetreivedProperty == currentUpdatedProperty)
                        {
                            retrievedCustomer.CustomerDataRecords[j].Value = updatedCustomer.CustomerDataRecords[i].Value;
                        }
                    }

                    var valueToUpdateOnRetrievedCustomer = retrievedCustomer.CustomerDataRecords.Where(x => x.Property.Name == currentUpdatedProperty).Select(p => p.Value).FirstOrDefault();
                    valueToUpdateOnRetrievedCustomer = updatedCustomer.CustomerDataRecords[i].Value;
                }

                editedCustomer = _customerService.UpdateCustomerRecords(retrievedCustomer);
            }
            if (editedCustomer)
            {
                return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new { success = false }, JsonRequestBehavior.AllowGet));
            }
        }
        public async Task <JsonResult> GetJsonByCustomerId(string id)
        {
            if (id == null || id == String.Empty)
            {
                var data = "{Customer Id does not exist}" as object;
                //throw new ValidationException(Json(data, "application/json", Encoding.UTF8););
            }

            AggregateCustomer retrievedCustomerRecord = _customerService.GetCustomerByID(id);

            retrievedCustomerRecord.CustomerId = id;

            EnsureProperties(retrievedCustomerRecord);

            var serializableCustomerReocrd = Mapper.Map <AggregateCustomer, AggregateCustomerViewModel>(retrievedCustomerRecord);

            var jsonCustomerRecord = AggregateCustomerViewModel.Serialize(serializableCustomerReocrd);

            var jsonToReturn = Json(serializableCustomerReocrd, "application/json", Encoding.UTF8, JsonRequestBehavior.AllowGet);

            return(jsonToReturn);
        }
        public ActionResult EditPosted([JsonBinder] AggregateCustomerViewModel modelString)
        //public async Task<ActionResult> Edit(AggregateCustomer customerRecord)
        {
            var editedCustomerId = ViewBag.CustomerId;

            if (ModelState.IsValid)
            {
                AggregateCustomerViewModel customerRecord = modelString;
                AggregateCustomer          newRecord      = new AggregateCustomer();
                newRecord.CustomerDataRecords = new List <CustomerRecord>();
                var retrievedCustomer = _customerService.GetCustomerByID(customerRecord.CustomerId);
                EnsureProperties(retrievedCustomer);
                foreach (var updatedRecord in customerRecord.CustomerDataRecords)
                {
                    var mappedRecord = Mapper.Map <CustomerRecordViewModel, CustomerRecord>(updatedRecord);
                }

                var editedCustomer =
                    _customerService.UpdateCustomerRecords(retrievedCustomer);
                return(RedirectToAction("Index"));
            }
            return(View(modelString));
        }
        public async Task <JsonResult> GetNewlyCreatedCustomerJson()
        {
            AggregateCustomer newlyCreatedCustomer = new AggregateCustomer();

            newlyCreatedCustomer.CustomerDataRecords = new List <CustomerRecord>();

            var newlyCreatedCustomerId = Guid.NewGuid().ToString();

            newlyCreatedCustomer.CustomerId = newlyCreatedCustomerId;
            var currentPropertySet = _propertyService.GetAllProperties();

            foreach (var property in currentPropertySet)
            {
                CustomerRecord newCustomerRecord = new CustomerRecord();
                newCustomerRecord.RecordId = Guid.NewGuid();

                Property newProperty = new Property();
                Backend.EntityFramework.Type newType = new Backend.EntityFramework.Type();
                newCustomerRecord.CustomerId = newlyCreatedCustomerId;
                newCustomerRecord.Property   = newProperty;
                newCustomerRecord.Type       = newType;
                newCustomerRecord.Property   = property;
                newCustomerRecord.PropertyId = property.PropertyId;
                // Only setting this property for convenience in a more complete system/example this would be dealt with in a similar way to properties.
                newCustomerRecord.TypeId = "1";
                newlyCreatedCustomer.CustomerDataRecords.Add(newCustomerRecord);
            }


            var serializableCustomerReocrd = Mapper.Map <AggregateCustomer, AggregateCustomerViewModel>(newlyCreatedCustomer);

            var jsonCustomerRecord = AggregateCustomerViewModel.Serialize(serializableCustomerReocrd);

            var jsonToReturn = Json(serializableCustomerReocrd, "application/json", Encoding.UTF8, JsonRequestBehavior.AllowGet);

            return(jsonToReturn);
        }
예제 #15
0
        public void CanCreateNewCustomer()
        {
            try
            {
                AggregateCustomer customer = new AggregateCustomer();
                customer.CustomerId          = Guid.NewGuid().ToString();
                customer.CustomerDataRecords = new List <CustomerRecord>();
                var nameRecord = new CustomerRecord
                {
                    CustomerId = "4",
                    TypeId     = "1",
                    PropertyId = "1",
                    Value      = "NewCustomer",
                    Type       = new Backend.EntityFramework.Type {
                        TypeId = "1", Name = "Customer"
                    },
                    Property = new Backend.EntityFramework.Property {
                        PropertyId = "1", Name = "Name"
                    },
                    RecordId = Guid.NewGuid()
                };
                customer.CustomerDataRecords.Add(nameRecord);
                var ageRecord = new CustomerRecord
                {
                    CustomerId = "4",
                    TypeId     = "1",
                    PropertyId = "2",
                    Value      = "42",
                    Type       = new Backend.EntityFramework.Type {
                        TypeId = "1", Name = "Customer"
                    },
                    Property = new Backend.EntityFramework.Property {
                        PropertyId = "2", Name = "Age"
                    },
                    RecordId = Guid.NewGuid()
                };
                customer.CustomerDataRecords.Add(ageRecord);

                var customers         = _CustomerService.GetAllCustomers();
                var numberOfCustomers = customers.Count();
                Assert.AreEqual(3, numberOfCustomers);

                _CustomerService.CreateCustomer(customer);
                customers         = _CustomerService.GetAllCustomers();
                numberOfCustomers = customers.Count();
                Assert.AreEqual(4, numberOfCustomers);
                AggregateCustomer retreivedCreatedCustomer = _CustomerService.GetCustomerByID("4");
                CustomerRecord    createdNameRecord        = customer.CustomerDataRecords.Where(r => r.Property.Name == "Name").FirstOrDefault();
                Assert.AreEqual(createdNameRecord.Property.Name, "Name");
                Assert.AreEqual(createdNameRecord.Type.Name, "Customer");
                Assert.AreEqual(createdNameRecord.Value, "NewCustomer");
                CustomerRecord createdAgeRecord = customer.CustomerDataRecords.Where(r => r.Property.Name == "Age").FirstOrDefault();
                Assert.AreEqual(createdAgeRecord.Property.Name, "Age");
                Assert.AreEqual(createdAgeRecord.Type.Name, "Customer");
                Assert.AreEqual(createdAgeRecord.Value, "42");
            }
            catch (Exception ex)
            {
                Assert.Fail("Expected no exception, but got: " + ex.Message);
            }
        }