public ActionResult Create(Supplier supplier) { //Validiation if (!Authorized(RoleType.OrdersWriter)) return Error(Loc.Dic.error_no_permission); if (!ModelState.IsValid) return Error(ModelState); //Creation SuppliersRepository.Messeges createMessege; using (SuppliersRepository supplierRep = new SuppliersRepository(CurrentUser.CompanyId)) createMessege = supplierRep.Create(supplier); //BackToUI if (createMessege == SuppliersRepository.Messeges.CreatedSuccessfully) return RedirectToAction("Index"); else if (createMessege == SuppliersRepository.Messeges.Error_ExternalIdExist) return Error(Loc.Dic.error_externalIdAlreadyExist); return Error(Loc.Dic.error_suppliers_create_error); }
public JsonResult AjaxCreate(Supplier supplier) { if (Authorized(RoleType.OrdersWriter)) { supplier.CompanyId = CurrentUser.CompanyId; SuppliersRepository.Messeges messege; using (SuppliersRepository supplierRep = new SuppliersRepository(CurrentUser.CompanyId)) messege = supplierRep.Create(supplier); if (messege == SuppliersRepository.Messeges.CreatedSuccessfully) return Json(new { success = true, message = String.Empty, newSupplierId = supplier.Id.ToString() }, JsonRequestBehavior.AllowGet); else return Json(new { success = false, message = Loc.Dic.error_suppliers_create_error }, JsonRequestBehavior.AllowGet); } else { return Json(new { success = false, message = Loc.Dic.error_no_permission }, JsonRequestBehavior.AllowGet); } }
/// <summary> /// Create a new Supplier object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="companyId">Initial value of the CompanyId property.</param> /// <param name="creationDate">Initial value of the CreationDate property.</param> /// <param name="name">Initial value of the Name property.</param> /// <param name="isCanceled">Initial value of the IsCanceled property.</param> public static Supplier CreateSupplier(global::System.Int32 id, global::System.Int32 companyId, global::System.DateTime creationDate, global::System.String name, global::System.Boolean isCanceled) { Supplier supplier = new Supplier(); supplier.Id = id; supplier.CompanyId = companyId; supplier.CreationDate = creationDate; supplier.Name = name; supplier.IsCanceled = isCanceled; return supplier; }
/// <summary> /// Deprecated Method for adding a new object to the Suppliers EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToSuppliers(Supplier supplier) { base.AddObject("Suppliers", supplier); }
public static string ImportSuppliers(Stream stream, int companyId) { const int EXTERNALID = 0; const int NAME = 1; List<Supplier> toAddSuppliers = new List<Supplier>(); byte[] fileBytes = new byte[stream.Length]; stream.Read(fileBytes, 0, Convert.ToInt32(stream.Length)); string fileContent = System.Text.Encoding.Default.GetString(fileBytes); string[] fileLines = fileContent.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); int firstValuesLine = 0; bool noErros = true; string errorType = String.Empty; using (SuppliersRepository suppliersRep = new SuppliersRepository(companyId)) { for (int i = firstValuesLine; i < fileLines.Length; i++) { string[] lineValues = fileLines[i].Split('\t'); for (int vIndex = 0; vIndex < lineValues.Length; vIndex++) { lineValues[vIndex] = lineValues[vIndex].Replace("\"", ""); } Supplier newSupplier; if (!(int.Parse(lineValues[EXTERNALID]) > 0)) { errorType = Loc.Dic.error_invalid_form; break; } if (lineValues[NAME] == null) { errorType = Loc.Dic.error_invalid_form; break; } try { newSupplier = new Supplier() { CompanyId = companyId, ExternalId = lineValues[EXTERNALID], Name = lineValues[NAME], }; } catch { noErros = false; errorType = Loc.Dic.Error_FileParseError; break; } List<Supplier> existingSuppliers = suppliersRep.GetList().Where(x => x.CompanyId == companyId && x.ExternalId == newSupplier.ExternalId).ToList(); if (existingSuppliers.Count == 0) toAddSuppliers.Add(newSupplier); else { foreach (Supplier supplier in existingSuppliers) { supplier.Name = lineValues[NAME]; suppliersRep.Update(supplier); } } } if (!suppliersRep.AddList(toAddSuppliers)) { noErros = false; errorType = Loc.Dic.error_database_error; } } if (!noErros) return errorType; return "OK"; }
public ActionResult PartialDetails(Supplier supplier) { return PartialView(supplier); }
public ActionResult Edit(Supplier supplier) { if (!Authorized(RoleType.SystemManager)) return Error(Loc.Dic.error_no_permission); if (ModelState.IsValid) { Supplier supplierFromDB; bool wasUpdated; using (SuppliersRepository supplierRep = new SuppliersRepository(CurrentUser.CompanyId)) { supplierFromDB = supplierRep.GetEntity(supplier.Id); if (supplierFromDB == null) return Error(Loc.Dic.error_supplier_not_found); if (supplierFromDB.CompanyId != CurrentUser.CompanyId) return Error(Loc.Dic.error_no_permission); supplierFromDB.Name = supplier.Name; supplierFromDB.ExternalId = supplier.ExternalId; supplierFromDB.Activity_Hours = supplier.Activity_Hours; supplierFromDB.Additional_Phone = supplier.Additional_Phone; supplierFromDB.Address = supplier.Address; supplierFromDB.Branch_line = supplier.Branch_line; supplierFromDB.Crew_Number = supplier.Crew_Number; supplierFromDB.Customer_Number = supplier.Customer_Number; supplierFromDB.EMail = supplier.EMail; supplierFromDB.Fax = supplier.Fax; supplierFromDB.Notes = supplier.Notes; supplierFromDB.Phone_Number = supplier.Phone_Number; supplierFromDB.Presentor_name = supplier.Presentor_name; supplierFromDB.VAT_Number = supplier.VAT_Number; if (supplierRep.Update(supplierFromDB) != null) return RedirectToAction("Index"); else return Error(Loc.Dic.error_database_error); } } else { return Error(ModelState); } }