Пример #1
0
        public async Task <IActionResult> Index()
        {
            // Fetching Meals into local JArray
            JArray mealArray = await MealMethods.GetMeals();

            // Converting JArray items to Collection object of given type
            List <Meal> meals = mealArray.ToObject <List <Meal> >();

            Domain.Client client = _clientService.GetClientByEmail(User.Identity.Name);
            List <Order>  orders = new List <Order>();

            foreach (var item in _orderService.GetOrders())
            {
                if (item.Client == client)
                {
                    orders.Add(item);
                }
            }

            List <OrderMeal>     orderMeals = _orderService.GetOrderMeals();
            List <OrderMealDish> mealDishes = _orderService.GetOrderMealDishes();


            double birthdayDiscount = 0;

            ViewBag.OrderMeals = orderMeals;
            ViewBag.MealDishes = mealDishes;
            ViewBag.Meals      = meals;
            ViewBag.Birthday   = birthdayDiscount;
            ViewBag.Client     = client;
            return(View(orders));
        }
Пример #2
0
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var client = new Domain.Client
                {
                    FirstName   = model.FirstName,
                    LastName    = model.LastName,
                    Email       = model.Email,
                    Birthday    = model.Birthday,
                    City        = model.City,
                    Street      = model.Street,
                    HouseNumber = model.HouseNumber,
                    Addition    = model.Addition,
                    PostalCode  = model.PostalCode,
                    Gluten      = model.Gluten,
                    Diabetes    = model.Diabetes,
                    Salt        = model.Salt
                };

                _clientService.CreateClient(client);

                var user = new AbstractUser
                {
                    FirstName       = model.FirstName,
                    LastName        = model.LastName,
                    Password        = model.Password,
                    ConfirmPassword = model.ConfirmPassword,
                    UserName        = model.Email,
                    Email           = model.Email
                };

                var roleExist = _roleManager.RoleExistsAsync("Client").Result;
                if (!roleExist)
                {
                    //create the roles and seed them to the database
                    IdentityRole Client = new IdentityRole()
                    {
                        Name = "Client"
                    };
                    await _roleManager.CreateAsync(Client);
                }

                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await _userManager.AddToRoleAsync(user, "Client");

                    return(RedirectToAction("Index", "Home"));
                }

                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }
            }
            return(View(model));
        }
Пример #3
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            ClientBussines clientBusines = new ClientBussines();

            Domain.Client client = new Domain.Client(tbUserClient.Text, tbPassClient.Text, tbNameClient.Text, tbBorn.Text);
            clientBusines.insertClient(client);
            Response.Redirect("~/ Clients / ViewClient.aspx");
        }
Пример #4
0
 public static void ToEntity(this ClientModel model, ref Client entity)
 {
     entity.Nume = model.Nume;
     entity.Prenume = model.Prenume;
     entity.Strada = model.Adresa;
     entity.Istoric = model.Istoric;
     entity.Localitate = model.Localitate;
     entity.CodPostal = model.CodPostal;
     entity.JudetID = model.JudetId;
 }
Пример #5
0
        /// <summary>
        /// Function to save Client details.
        /// </summary>
        /// <param name="client">Client information.</param>
        public void InsertOrUpdate(Client client)
        {
            if (client == null)
            {
                throw new ArgumentNullException(ClientConstant);
            }

            if (client.ClientID == default(int))
            {
                this.unitOfWork.Context.Entry(client).State = EntityState.Added;
            }
            else
            {
                this.unitOfWork.Context.Entry(client).State = EntityState.Modified;
            }
        }
        public void Has_BirthDay_Discount()
        {
            Domain.Cart target = new Domain.Cart();
            meal1.MealDishes = new List <Dish>()
            {
                dish, dish2, dish3
            };
            meal2.MealDishes = new List <Dish>()
            {
                dish, dish2, dish3
            };
            meal3.MealDishes = new List <Dish>()
            {
                dish, dish2, dish3
            };

            target.AddItem(meal2, DateTime.Now.DayOfWeek);
            target.AddItem(meal3, DateTime.Now.DayOfWeek);
            target.AddItem(meal1, DateTime.Now.DayOfWeek);

            var    lines = target.Lines;
            double total = target.ComputeTotalValue(lines);

            Assert.Equal((17.85 * 3), total);

            Domain.Client client = new Domain.Client()
            {
                FirstName = "Tester",
                LastName  = "Test",
                Birthday  = DateTime.Now.Date,
                Email     = "*****@*****.**"
            };

            bool sameDate = target.MealOnBirthDay(client.Birthday);

            Assert.True(sameDate);

            if (sameDate)
            {
                total -= MealMethods.GetMealPrice(meal1);
            }

            Assert.Equal(35.7, total);
        }
Пример #7
0
        public static externalDTO.Client MapFromDomain(internalDTO.Client client)
        {
            var res = client == null ? null : new externalDTO.Client
            {
                Id                = client.Id,
                ClientGroupId     = client.ClientGroupId,
                ClientGroup       = DAL.App.EF.Mappers.ClientGroupMapper.MapFromDomain(client.ClientGroup),
                CompanyName       = client.CompanyName,
                Address           = client.Address,
                ContactPerson     = client.ContactPerson,
                Phone             = client.Phone,
                From              = client.From,
                CompanyAndAddress = client.CompanyAndAddress,
//                Bills = client.Bills.Select(e => BillMapper.MapFromDomain(e)).ToList(),
//                ProductsForClient = client.ProductsForClient.Select(e => ProductForClientMapper.MapFromDomain(e)).ToList()
            };

            return(res);
        }
Пример #8
0
        public IActionResult Update()
        {
            // Retrieve Identity user
            var allUsers = _abstractUserService.GetUsers();

            AbstractUser getUser = new AbstractUser();

            foreach (var item in allUsers)
            {
                if (item.Email == User.Identity.Name)
                {
                    getUser = item;
                }
            }

            // Retrieve Client user
            Domain.Client client = _clientService.Client.FirstOrDefault(c => c.Email == getUser.Email);

            // Arrage return model
            UpdateViewModel model = new UpdateViewModel()
            {
                FirstName       = client.FirstName,
                LastName        = client.LastName,
                Email           = client.Email,
                Birthday        = client.Birthday,
                City            = client.City,
                Street          = client.Street,
                HouseNumber     = client.HouseNumber,
                Addition        = client.Addition,
                PostalCode      = client.PostalCode,
                Gluten          = client.Gluten,
                Diabetes        = client.Diabetes,
                Salt            = client.Salt,
                Password        = getUser.Password,
                ConfirmPassword = getUser.ConfirmPassword
            };

            return(View(model));
        }
Пример #9
0
        public ClientMember(conClientesIntegrantes conClientesIntegrantes )
        {
            this.Id = conClientesIntegrantes.ID;
            this.Nombre = conClientesIntegrantes.Nombre;
            this.Apellido = conClientesIntegrantes.Apellido;
            this.TipoIntegrante = conClientesIntegrantes.TipoIntegrante;
            this.NroAfiliado = conClientesIntegrantes.NroAfiliado;
            this.Documento = conClientesIntegrantes.NroDocumento;
            this.FecNacimiento = conClientesIntegrantes.FecNacimiento;
            if (conClientesIntegrantes.ClienteId != null)
            {
                this.Cliente = new Client(conClientesIntegrantes.ClienteId);
                this.AbreviaturaId = conClientesIntegrantes.ClienteId.AbreviaturaId;
            }

            this.Domicilio = new Domicile(conClientesIntegrantes.Domicilio);
            this.Localidad = new Locality(conClientesIntegrantes.LocalidadId);
            this.Sexo = conClientesIntegrantes.Sexo;
            
            this.SetTelephoneData(conClientesIntegrantes);
            this.SetPatient();
            this.SetAge();

        }
Пример #10
0
        /// <summary>
        /// Function to validate client delete information.
        /// </summary>
        /// <param name="client">client information</param>
        /// <returns>
        /// List of errors
        /// </returns>
        public ErrorListItem ValidateDelete(Client client)
        {
            if (client == null)
            {
                throw new ArgumentNullException(ClientConstant);
            }

            return this.unitOfWork.Context.ValidateClientDeleteInformation(client.ClientID > 0 ? client.ClientID : default(int?)).FirstOrDefault();
        }
Пример #11
0
        /// <summary>
        /// Function to validate client.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="userId">The user identifier.</param>
        /// <returns>
        /// List of errors
        /// </returns>
        public ErrorListItem Validate(Client client, int userId)
        {
            if (client == null)
            {
                throw new ArgumentNullException(ClientConstant);
            }

            return this.unitOfWork.Context.ValidateClientInformation(client.Name, client.DoNotListFlag, client.ClientID > 0 ? client.ClientID : default(int?), userId).FirstOrDefault();
        }
Пример #12
0
        /// <summary>
        /// Function to delete client information.
        /// </summary>
        /// <param name="id">client id</param>
        public void Delete(int id)
        {
            var client = new Client
            {
                ClientID = id
            };

            this.unitOfWork.Context.Entry(client).State = EntityState.Deleted;
        }
Пример #13
0
        public async Task <IActionResult> Checkout(CheckoutViewModel model)
        {
            ViewBag.Lines = _cart.Lines;


            if (!_cart.Lines.Any())
            {
                ModelState.AddModelError(string.Empty, "Sorry, your shoppingcart is empty!");
                return(View());
            }

            if (!_cart.IsValid())
            {
                ModelState.AddModelError(string.Empty, "You need to order at least 4 meals between monday and friday!");
                return(View());
            }
            if (ModelState.IsValid)
            {
                try
                {
                    Dictionary <Meal, MealSize> meals = new Dictionary <Meal, MealSize>();
                    List <CartLine>             lines = _cart.Lines;

                    // Fetching Dishes into local JArray
                    JArray dishArray = await DishMethods.GetDishes();

                    // Converting JArray items to Collection object of given type
                    List <Dish> dishes = dishArray.ToObject <List <Dish> >();

                    Domain.Client client = _clientService.GetClientByEmail(User.Identity.Name);

                    foreach (var item in model.CheckoutItems)
                    {
                        foreach (var lineItem in _cart.Lines)
                        {
                            if (item.Key == lineItem.Meal.Id)
                            {
                                meals.Add(lineItem.Meal, item.Value);
                            }
                        }
                    }


                    foreach (var dish in dishes)
                    {
                        foreach (var meal in lines)
                        {
                            foreach (var mealDish in meal.Meal.Dishes)
                            {
                                if (mealDish.DishId == dish.Id)
                                {
                                    meal.Meal.MealDishes.Add(dish);
                                }
                            }
                        }
                    }
                    double total = _cart.ComputeTotalValue(lines);


                    //Check meal sizes to obtain 20 % or decrement 20 % of total price
                    foreach (var item in meals)
                    {
                        if (item.Value == MealSize.Large)
                        {
                            total += (Domain.Extensions.MealMethods.GetMealPrice(item.Key) * 0.2);
                        }

                        if (item.Value == MealSize.Small)
                        {
                            total -= (Domain.Extensions.MealMethods.GetMealPrice(item.Key) * 0.2);
                        }
                    }


                    List <OrderMeal>     orderMeals      = new List <OrderMeal>();
                    List <OrderMealDish> orderMealDishes = new List <OrderMealDish>();
                    foreach (var item in meals)
                    {
                        bool bdm = item.Key.DateValid == client.Birthday ? true : false;
                        foreach (var dish in item.Key.MealDishes)
                        {
                            orderMealDishes.Add(new OrderMealDish {
                                Name = dish.Name, Price = dish.Price, MealId = item.Key.Id
                            });
                        }
                        orderMeals.Add(new OrderMeal
                        {
                            MealId       = item.Key.Id,
                            MealSize     = item.Value,
                            Dishes       = orderMealDishes,
                            MealDate     = item.Key.DateValid,
                            birthdayMeal = bdm
                        });
                    }


                    Order order = new Order()
                    {
                        Client     = client,
                        Meals      = orderMeals,
                        TotalPrice = total
                    };

                    try
                    {
                        _orderService.CreateOrder(order);
                        client.Orders.Add(order);
                        _cart.Clear();

                        return(RedirectToAction("Index", "Home"));
                    }
                    catch (Exception)
                    {
                        throw new Exception();
                    }
                }
                catch (Exception)
                {
                    throw new Exception();
                }
            }
            return(View());
        }
Пример #14
0
 public IHttpActionResult Put(int clientId, Client client)
 {
     Client existing = Context.Clients.FirstOrDefault(i => i.Id == clientId);
     if (existing == null)
     {
         return NotFound();
     }
     else
     {
         existing.FirstName = client.FirstName;
         existing.LastName = client.LastName;
         Context.SaveChanges();
         return Ok(existing);
     }
 }
Пример #15
0
 /// <summary>
 /// Create a new Client object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="nume">Initial value of the Nume property.</param>
 /// <param name="prenume">Initial value of the Prenume property.</param>
 /// <param name="strada">Initial value of the Strada property.</param>
 /// <param name="istoric">Initial value of the Istoric property.</param>
 /// <param name="judetID">Initial value of the JudetID property.</param>
 public static Client CreateClient(global::System.Int32 id, global::System.String nume, global::System.String prenume, global::System.String strada, global::System.String istoric, global::System.Int32 judetID)
 {
     Client client = new Client();
     client.ID = id;
     client.Nume = nume;
     client.Prenume = prenume;
     client.Strada = strada;
     client.Istoric = istoric;
     client.JudetID = judetID;
     return client;
 }
Пример #16
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Clients EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToClients(Client client)
 {
     base.AddObject("Clients", client);
 }