コード例 #1
0
        public ActionResult RegisterMigration(RegisterProductIngridientModel model)
        {
            var result = new Dictionary<string, object>
            {
                ["isSuccess"] = false,
                ["error"] = "Something was wrong. Migration has not been added to the database"
            };

            if (!this.ModelState.IsValid) return this.Json(result, JsonRequestBehavior.DenyGet);

            var helper = new HelperRepository();

            var insertedCustomerId = helper.InsertOrUpdateProductIngridient(
                model.ProductId,
                model.IngridientId,
                model.Weight);

            if (!insertedCustomerId) return this.Json(result, JsonRequestBehavior.DenyGet);

            result["success"] = $"Migration between {helper.GetProduct(model.ProductId).Name} and {helper.GetIngridient(model.IngridientId).Name} has successfully added to the database";
            result["model"] = HelperConverter.GetProductIngridientRowJsonString(model.ProductId, model.IngridientId);

            result["isSuccess"] = true;
            return this.Json(result, JsonRequestBehavior.DenyGet);
        }
コード例 #2
0
        public ActionResult Register(RegisterCustomerModel model)
        {
            var result = new Dictionary<string, object>
            {
                ["isSuccess"] = false,
                ["error"] = "Something was wrong. Customer has not been added to the database"
            };

            if (!this.ModelState.IsValid) return this.Json(result, JsonRequestBehavior.DenyGet);

            var hashedPassword = HelperConverter.DoubleMD5Hash(model.Password);
            var helper = new HelperRepository();

            var insertedCustomerId = helper.InsertCustomer(
                model.FirstName,
                model.MiddleName,
                model.LastName);

            helper.InsertUser(insertedCustomerId,
                model.Email,
                hashedPassword,
                model.RoleId);
                
            result["success"] = $"Customer {model.FirstName} {model.LastName} has successfully added to the database";
            result["model"] = HelperConverter.GetCustomerRowJsonString(insertedCustomerId);

            result["isSuccess"] = true;
            return this.Json(result, JsonRequestBehavior.DenyGet);
        }
コード例 #3
0
        public static string GetProductRowJsonString(int productId)
        {
            var helper = new HelperRepository();
            var product = helper.GetProduct(productId);

            var result = new Dictionary<string, object>
            {
                ["name"] = product.Name,
                ["price"] = product.Price,
                ["id"] = product.Id
            };

            return new JavaScriptSerializer().Serialize(result);
        }
コード例 #4
0
        public static string GetIngridientRowJsonString(int ingridientId)
        {
            var helper = new HelperRepository();
            var ingridient = helper.GetIngridient(ingridientId);

            var result = new Dictionary<string, object>
            {
                ["name"] = ingridient.Name,
                ["description"] = ingridient.Description ?? string.Empty,
                ["id"] = ingridient.Id
            };

            return new JavaScriptSerializer().Serialize(result);
        }
コード例 #5
0
        public static string GetCustomerRowJsonString(int customerId)
        {
            var helper = new HelperRepository();
            var customer = helper.GetCustomer(customerId);
            var user = helper.GetUserByCustomerId(customerId);

            var result = new Dictionary<string, object>
            {
                ["firstname"] = customer.Name,
                ["middlename"] = customer.MiddleName ?? string.Empty,
                ["lastname"] = customer.LastName,
                ["email"] = user.Email,
                ["role"] = helper.GetRoleNameById(user.RoleId),
                ["id"] = customerId
            };

            return new JavaScriptSerializer().Serialize(result);
        }
コード例 #6
0
        public static string GetOrderRowJsonString(int orderId)
        {
            var helper = new HelperRepository();
            var order = helper.GetOrder(orderId);
            var customer = helper.GetCustomer(order.CustomerId);
            var product = helper.GetProduct(order.ProductId);

            var result = new Dictionary<string, object>
            {
                ["customername"] = $"{customer.LastName}, {customer.Name}",
                ["productname"] = product.Name,
                ["quantity"] = order.Count,
                ["totalamount"] = order.Count*product.Price,
                ["date"] = order.Date.ToString("f"),
                ["id"] = orderId
            };

            return new JavaScriptSerializer().Serialize(result);
        }
コード例 #7
0
        public ActionResult Delete(int id)
        {
            var result = new Dictionary<string, object>
            {
                ["isSuccess"] = false,
                ["error"] = "Something was wrong. Customer not found"
            };

            var helper = new HelperRepository();
            var customer = helper.GetCustomer(id);

            if (helper.DeleteCustomer(id))
            {
                result["success"] = $"Customer {customer.Name} {customer.LastName} has been successfully deleted";
                result["isSuccess"] = true;
            }

            return this.Json(result);
        }
コード例 #8
0
        public ActionResult Register(RegisterProductModel model)
        {
            var result = new Dictionary<string, object>
            {
                ["isSuccess"] = false,
                ["error"] = "Something was wrong. Product has not been added to the database"
            };

            if (!this.ModelState.IsValid) return this.Json(result, JsonRequestBehavior.DenyGet);

            var insertedProductId = new HelperRepository().InsertProduct(
                model.Name,
                model.Price);
                
            result["success"] = $"Product {model.Name} has successfully added to the database";
            result["model"] = HelperConverter.GetProductRowJsonString(insertedProductId);

            result["isSuccess"] = true;
            return this.Json(result, JsonRequestBehavior.DenyGet);
        }
コード例 #9
0
        public ActionResult Signup(RegisterCustomerModel model)
        {
            model.RoleId = 1;
            var message = "Something was wrong. You are has not been registered";

            if (!this.ModelState.IsValid)
                return this.Json(message, JsonRequestBehavior.DenyGet);

            var hashedPassword = HelperConverter.DoubleMD5Hash(model.Password);
            var helper = new HelperRepository();

            var insertedCustomerId = helper.InsertCustomer(
                model.FirstName,
                model.MiddleName,
                model.LastName);

            helper.InsertUser(insertedCustomerId,
                model.Email,
                hashedPassword,
                model.RoleId);

            return this.RedirectToAction("Login", "Account");
        }
コード例 #10
0
        public ActionResult Register(RegisterOrderModel model)
        {
            var result = new Dictionary<string, object>
            {
                ["isSuccess"] = false,
                ["error"] = "Something was wrong. Order has not been added to the database"
            };

            if (this.ModelState.IsValid)
            {
                var helper = new HelperRepository();

                var insertedOrderId = helper.InsertOrder(
                    model.CustomerId,
                    model.ProductId,
                    model.Count);
                
                result["success"] = "Product has been sold";
                result["model"] = HelperConverter.GetOrderRowJsonString(insertedOrderId);
                result["isSuccess"] = true;
            }
            return this.Json(result, JsonRequestBehavior.DenyGet);
        }
コード例 #11
0
 public ActionResult EmailIsExist(string email)
 {
     var isExist = new HelperRepository().EmailIsExist(email);
     return this.Json(new { isExist = isExist });
 }
コード例 #12
0
        public static string GetProductIngridientRowJsonString(int productId, int ingridientId)
        {
            var helper = new HelperRepository();
            var productIngrient = helper.GetProductIngridient(productId, ingridientId);

            var result = new Dictionary<string, object>
            {
                ["name"] = productIngrient.Ingridient.Name,
                ["weight"] = productIngrient.Weight,
                ["productId"] = productId,
                ["ingridientId"] = ingridientId
            };

            return new JavaScriptSerializer().Serialize(result);
        }