Ejemplo n.º 1
0
        public static void AddCustomer(Customer customer, ICollection<Plan> plans)
        {
			int customerId = CommonDAL.AddEntity<Customer>(customer, c => c.Name == customer.Name && c.FamilyName == customer.FamilyName && c.Street == customer.Street);

			//if (plans != null && plans.Count > 0)
			//{
			//	using (PosManagerContext ctx = new PosManagerContext())
			//	{
			//		foreach (Plan plan in plans)
			//		{
			//			plan.CustomerId = customerId;
			//			CommonDAL.AddEntity<Plan>(plan, p => p.CustomerId == plan.CustomerId && p.PlanTypeId == plan.PlanTypeId);
			//		}
			//	}
			//}
        }
Ejemplo n.º 2
0
		public static void UpdateCustomer(Customer customer, ICollection<Plan> plans)
		{
			CommonDAL.UpdateEntity<Customer>(customer);

			//using (PosManagerContext ctx = new PosManagerContext())
			//{
			//	if (plans != null && plans.Count > 0)
			//	{
			//		foreach (Plan plan in plans)
			//		{
			//			if (!plan.EntityExists<Plan>(ctx, p => p.CustomerId == plan.CustomerId && p.PlanTypeId == plan.PlanTypeId))
			//			{
			//				CommonDAL.AddEntity<Plan>(plan, p => p.CustomerId == plan.CustomerId && p.PlanTypeId == plan.PlanTypeId);
			//			}
			//			else
			//			{
			//				CommonDAL.UpdateEntity<Plan>(plan);
			//			}
			//		}
			//	}
			//}
		}
		public IHttpActionResult UpdateCustomer([FromBody]CustomerDTO customerDTO)
        {
			ApiStatusMessage statusMsg = new ApiStatusMessage();
			ICollection<Plan> plans = null;

			try
			{
				Customer customer = new Customer()
				{
					Id = customerDTO.Id,
					Name = customerDTO.Name,
					FamilyName = customerDTO.FamilyName,
					Street = customerDTO.Street,
					ZipCode = customerDTO.ZipCode,
					City = customerDTO.City,
					CountryCode = customerDTO.CountryCode,
					PhoneNumber = customerDTO.PhoneNumber,
					Email = customerDTO.Email
				};

				//if (customerDTO.PlanTypes != null && customerDTO.PlanTypes.Count > 0)
				//{
				//	plans = customerDTO.PlanTypes.Select(pt => new Plan()
				//	{
				//		CustomerId = customer.Id,
				//		PlanTypeId = pt.Id,
				//		DateCreated = DateTime.Now,
				//		DateEnds = DateTime.Now.AddDays(pt.Duration),

				//		Discounts = pt.DiscountTypes.Select(dt => new Discount()
				//		{
				//			DiscountTypeId = dt.Id,
				//			IsActive = false,
				//			RoundsCounter = dt.Rounds,							
				//			DateCreated = DateTime.Now,
				//			DateEnds = DateTime.Now.AddDays(pt.Duration)
				//		}).ToList()
				//	})
				//	.ToList();
				//}

				CustomersModule.UpdateCustomer(customer, plans);
				statusMsg.ApiResponseStatusCode = ApiResponseStatusCode.Success;
				statusMsg.ApiStatusPlainText = ApiStatusMessages.Customer_Update_Success;
			}
            catch(Exception e)
            {
				statusMsg.ApiStatusPlainText = ApiStatusMessages.Customer_Update_Failure;
				statusMsg.ApiResponseStatusCode = ApiResponseStatusCode.CRUDoperationError;
                statusMsg.StackTrace = e.StackTrace;
            }

            return new HttpStatusMessageActionResult(HttpStatusCode.Accepted, statusMsg, Request);
        }