public ActionResult NewObject([FromBody] Objects[] objects) { if (_context.Objects.Where( o => o.BuildingId == objects[0].BuildingId && o.Floor == objects[0].Floor && o.Porch == objects[0].Porch && o.Number == objects[0].Number && o.ObjectTypeId == objects[0].ObjectTypeId).Count() > 0) { return(Json("Bu obyek artıq mövcuddur")); } string result = ""; try { Objects obj = new Objects(); obj.Porch = objects[0].Porch; obj.Floor = objects[0].Floor; obj.Number = objects[0].Number; obj.Squares = objects[0].Squares; obj.BuildingId = objects[0].BuildingId; obj.ObjectTypeId = objects[0].ObjectTypeId; _context.Add(obj); _context.SaveChanges(); result = "Əməliyyat uğurla tamamlandı!"; } catch (Exception ex) { result = ex.Message; } return(Json(result)); }
public ActionResult NewBuilding([FromBody] Building[] buildings) { string result = "Sistem xətası"; if (_context.Building.Where(n => n.Number == buildings[0].Number && n.Address == buildings[0].Address).Count() > 0) { return(Json("Bu məlumatlara uyğun bina mövcuddur")); } try { Building building = new Building(); building.Number = buildings[0].Number; building.Address = buildings[0].Address; _context.Add(building); _context.SaveChanges(); result = "Əməliyyat uğurla tamamlandı!"; } catch (Exception ex) { result = ex.Message; } return(Json(result)); }
public ActionResult NewDuration([FromBody] PaymentDuration[] paymentDurations) { string result = "Sistem xətası"; if (_context.PaymentDuration.Where(n => n.ContractDetailId == paymentDurations[0].ContractDetailId).ToList().Count != 0) { result = "Bu gecikmə üzrə qeyd mövcuddur"; return(Json(result)); } try { PaymentDuration paymentDuration = new PaymentDuration(); paymentDuration.ContractDetailId = paymentDurations[0].ContractDetailId; paymentDuration.PaymentDate = paymentDurations[0].PaymentDate; paymentDuration.Reason = paymentDurations[0].Reason; paymentDuration.CreateDate = DateTime.Now; _context.Add(paymentDuration); _context.SaveChanges(); result = "Əməliyyat uğurla tamamlandı"; return(Json(result)); } catch (SqlException ex) { result = ex.Message; return(Json(result)); } }
public ActionResult NewCustomer([FromBody] Customers[] customers) { if (_context.Customers.Where( c => c.Name == customers[0].Name && c.Surname == customers[0].Surname && c.DocNumber == customers[0].DocNumber && c.Phone == customers[0].Phone).Count() > 0) { return(Json("Bu müştəri artıq mövcuddur")); } string result = "Sistem xətası"; try { Customers customer = new Customers(); customer.Name = customers[0].Name; customer.Surname = customers[0].Surname; customer.Phone = customers[0].Phone; customer.Email = customers[0].Email; customer.DocNumber = customers[0].DocNumber; customer.CustomerTypeId = customers[0].CustomerTypeId; _context.Add(customer); _context.SaveChanges(); result = "Əməliyyat uğurla tamamlandı!"; } catch (Exception ex) { result = ex.Message; } return(Json(result)); }
public ActionResult NewCash([FromBody] Cash[] cashes) { string result = "Sistem xətası"; if (_context.Cash.Where(d => d.Defenition == cashes[0].Defenition && d.Number == cashes[0].Number).Count() > 0) { return(Json("Bu məlumatlara uyğun kassa mövcuddur")); } try { Cash cash = new Cash(); cash.Number = cashes[0].Number; cash.Defenition = cashes[0].Defenition; _context.Add(cash); _context.SaveChanges(); result = "Əməliyyat uğurla tamamlandı!"; } catch (Exception ex) { result = ex.Message; } return(Json(result)); }
public ActionResult NewSupportType([FromBody] SupportType[] supportTypes) { string result = "Sistem xətası"; try { SupportType supportType = new SupportType(); supportType.Defenition = supportTypes[0].Defenition; _context.Add(supportType); _context.SaveChanges(); result = "Əməliyyat uğurla tamamlandı!"; } catch (Exception ex) { result = ex.Message; } return(Json(result)); }
public ActionResult EditPayment([FromBody] Payments[] payments) { string result = "Sistem xətası"; try { Payments payment = new Payments(); payment.Id = payments[0].Id; payment.Amount = payments[0].Amount; payment.Explanation = payments[0].Explanation; //payment.Explanation2 = payments[0].Explanation2; //payment.Explanation3 = payments[0].Explanation3; //payment.TransactionTypeId = payments[0].TransactionTypeId; //payment.SignTypeId = payments[0].SignTypeId; //payment.CashId = payments[0].CashId; //if (payments[0].CostTypeId != null) //{ // payment.CostTypeId = payments[0].CostTypeId; //} //if (payments[0].ContractDetailId != null) //{ // payment.ContractDetailId = payments[0].ContractDetailId; //} //if (payments[0].IncomeTypeId != null) //{ // payment.IncomeTypeId = payments[0].IncomeTypeId; //} _context.Update(payment); _context.SaveChanges(); result = "Əməliyyat uğurla tamamlandı"; } catch (Exception ex) { result = ex.Message; } return(Json(result)); }
public ActionResult SaveContract([FromBody] Parameters param) { string result = "Sistem xətası"; //if (_context.Contract.Where(c=>c.CustomersId == param.CustomersId).Count() > 1) //{ // return Json("Müştərinin müqaviləsi mövcuddur"); //} Contract contract = new Contract(); contract.CustomersId = param.CustomersId; contract.Notes = param.Notes; contract.PaymentDate = param.PaymentDate; _context.Contract.Add(contract); _context.SaveChanges(); for (int i = 0; i < param.contractDetails.Length; i += 2) { //if (_context.ContractDetail.Where(c => c.ObjectsId == param.contractDetails[i].ObjectsId).Count() > 0) //{ // return Json("Obyekt başqa müqaviləyə bağlıdır"); //} ContractDetail contractDetail = new ContractDetail(); contractDetail.ContractId = contract.Id; contractDetail.SupportTypeId = param.contractDetails[i].SupportTypeId; contractDetail.ObjectsId = param.contractDetails[i].ObjectsId; contractDetail.ServicePrice = param.contractDetails[i].ServicePrice; _context.ContractDetail.Add(contractDetail); } //foreach (var item in param.contractDetails) //{ //} _context.SaveChanges(); result = "Əməliyyat uğurla tamamlandı"; return(Json(result)); }
public ActionResult NewObjectType([FromBody] ObjectType[] objectTypes) { if (_context.ObjectType.Where(o => o.Defenition == objectTypes[0].Defenition).Count() > 0) { return(Json("Bu obyekt növü mövcuddur")); } string result = "Sistem xətası"; try { ObjectType objectType = new ObjectType(); objectType.Defenition = objectTypes[0].Defenition; _context.Add(objectType); _context.SaveChanges(); result = "Əməliyyat uğurla tamamlandı!"; } catch (Exception ex) { result = ex.Message; } return(Json(result)); }
public ActionResult NewCostType([FromBody] CostType[] costTypes) { if (_context.CostType.Where(c => c.Defenition == costTypes[0].Defenition).Count() > 0) { return(Json("Bu məxaric növü mövcuddur")); } string result = "Sistem xətası"; try { CostType costType = new CostType(); costType.Defenition = costTypes[0].Defenition; _context.Add(costType); _context.SaveChanges(); result = "Əməliyyat uğurla tamamlandı!"; } catch (Exception ex) { result = ex.Message; } return(Json(result)); }
public ActionResult NewCustomerType([FromBody] CustomerType[] customerTypes) { if (_context.CustomerType.Where(d => d.Defenition == customerTypes[0].Defenition).Count() > 0) { return(Json("Bu müştəri tipi mövcuddur")); } string result = "Sistem xətası"; try { CustomerType customerType = new CustomerType(); customerType.Defenition = customerTypes[0].Defenition; _context.Add(customerType); _context.SaveChanges(); result = "Əməliyyat uğurla tamamlandı!"; } catch (Exception ex) { result = ex.Message; } return(Json(result)); }
public ActionResult NewIncomeType([FromBody] IncomeType[] incomeTypes) { if (_context.IncomeType.Where(i => i.Defenition == incomeTypes[0].Defenition).Count() > 0) { return(Json("Bu mədaxil növü mövcuddur")); } string result = "Sistem xətası"; try { IncomeType incomeType = new IncomeType(); incomeType.Defenition = incomeTypes[0].Defenition; _context.Add(incomeType); _context.SaveChanges(); result = "Əməliyyat uğurla tamamlandı!"; } catch (Exception ex) { result = ex.Message; } return(Json(result)); }
public ActionResult NewUser([FromBody] Users[] users) { string result = "Sistem xətası"; if (_context.Users.Where(n => n.Username == users[0].Username).Count() > 0) { result = "Daxil etdiyiniz istifadəçi adı artıq mövcuddur"; return(Json(result)); } else { try { Users user = new Users(); user.Username = users[0].Username; user.Password = Encrypt(users[0].Password.ToString()); user.IsAdmin = users[0].IsAdmin; _context.Add(user); _context.SaveChanges(); var query = "select * from permission"; //var connectionString = "Server=Namik;Database=AMSDBSECOND;Trusted_Connection=true;MultipleActiveResultSets=true"; DataTable dt; SqlConnection con = new SqlConnection(CheckPermission.GetConnection()); SqlCommand cmd = new SqlCommand(query, con); con.Open(); var a = cmd.ExecuteReader(); dt = new DataTable(); dt.Load(a); con.Close(); SqlCommand cmd2 = new SqlCommand(query, con); for (int i = 0; i < dt.Rows.Count; i++) { var c = dt.Rows[i]["Id"]; } SqlTransaction transaction = null; var connection = new SqlConnection(CheckPermission.GetConnection()); connection.Open(); transaction = connection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted, "Excell import"); var command = connection.CreateCommand(); command.CommandTimeout = 0; command.Transaction = transaction; for (int i = 0; i < dt.Rows.Count; i++) { command.CommandText += $@"insert into UserPermissions(UserId,PermissionId,Acces) values ({user.Id},{dt.Rows[i]["Id"]},0)"; } command.ExecuteNonQuery(); transaction.Commit(); result = "Əməliyyat uğurla tamamlandı"; return(Json(result)); } catch (Exception ex) { result = ex.Message; return(Json(result)); } } }