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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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"); }
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); }
public ActionResult EmailIsExist(string email) { var isExist = new HelperRepository().EmailIsExist(email); return this.Json(new { isExist = isExist }); }
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); }