public JsonResult AppRegistration(string json) { var result = new List <string>(); try { var inputJObject = JObject.Parse(json); var authJson = inputJObject["auth"]; var customerJson = inputJObject["customer"]; if (_db.Auth.FirstOrDefault(m => m.Username == (string)authJson["username"]) != null) { result.Add("Данный логин занят"); } if (_db.Customers.FirstOrDefault(m => m.IdNumber == (string)customerJson["idNumber"]) != null) { result.Add("По данному паспорту уже зарегестрирован аккаунт"); } if (result.Count == 0) { Customers customers = new Customers() { CustomerId = _db.Customers.Max(m => m.CustomerId) + 1, IdNumber = customerJson["idNumber"].ToString(), IdDocumentName = Convert.ToInt32(customerJson["idDocumentName"]), City = customerJson["city"].ToString(), Address = customerJson["address"].ToString(), DateOfBirth = DateTime.Parse(customerJson["dateOfBirth"].ToString()), Email = customerJson["email"].ToString(), FirstName = customerJson["firstName"].ToString(), SecondName = customerJson["secondName"].ToString(), PhoneNumber = customerJson["phoneNumber"].ToString() }; Auth auth = new Auth() { CustomerId = customers.CustomerId, Username = authJson["username"].ToString(), Password = authJson["password"].ToString(), UserType = 1 }; _db.Auth.Add(auth); _db.Customers.Add(customers); _db.SaveChanges(); } } catch { result.Add("Проблема с регистрацией."); } return(Json(result)); }
public string Delete(int orderId) { Contract contract = _context.Contract.FirstOrDefault(m => m.OrderId == orderId); Orders orders = _context.Orders.FirstOrDefault(m => m.OrderId == orderId); var list = _context.Details.Where(m => m.OrderId == orderId); _context.Details.RemoveRange(list); if (contract != null) { _context.Contract.Remove(contract); } if (orders != null) { _context.Orders.Remove(orders); } _context.SaveChanges(); return("Removed"); }
public string AppCreate(string json) { try { var inputJObject = JObject.Parse(json); Coments coments = new Coments() { CustomerId = Convert.ToInt32(inputJObject["customerId"]), BoatId = Convert.ToInt32(inputJObject["boatId"]), Coment = inputJObject["coment"].ToString(), ComentId = _context.Coments.Max(m => m.ComentId) + 1 }; _context.Coments.Add(coments); _context.SaveChanges(); return("ComentAdded"); } catch { return("Error"); } }
public string AppDelete(int customerId) { Customers customers = _context.Customers.Find(customerId); Auth auth = _context.Auth.FirstOrDefault(m => m.CustomerId == customerId); if (customers != null) { _context.Customers.Remove(customers); } if (auth != null) { _context.Auth.Remove(auth); } _context.SaveChanges(); return("Deleted"); }
public string SetProductionProcess(int idContract, int idProductionProcess) { try { Contract contract = _context.Contract.Find(idContract); if (contract != null) { contract.ProductionProcess = idProductionProcess; _context.Update(contract); _context.SaveChanges(); return("Contract updated"); } return("Contract is not found"); } catch { return("Error"); } }