public ActionResult Save(Company model, FormCollection collection) { var rep = Locator.GetService<ICompaniesRepository>(); // Сохраняем загруженный логотип var logo = Request.Files["LogoFile"]; string logoPath = null; if (logo != null && logo.ContentType.Contains("image") && logo.ContentLength > 0) { // Сохраняем файл var serverFilename = Path.GetFileNameWithoutExtension(Path.GetRandomFileName())+Path.GetExtension(logo.FileName); var directory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Uploads", "Logos"); var fullPath = Path.Combine(directory, serverFilename); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } // Преобразуем изображение var image = new WebImage(logo.InputStream); image.Resize(100, 100, true).Save(fullPath); logoPath = String.Format("/uploads/logos/{0}", serverFilename); } if (model.Id <= 0) { // Создаем компанию model.DateCreated = DateTime.Now; if (logoPath != null) { model.Logo = logoPath; } rep.Add(model); rep.SubmitChanges(); ShowSuccess("Компания успешно создана"); } else { // Ищем и редактируем компанию var comp = rep.Load(model.Id); if (comp == null) { ShowError("Компания не найдена"); return RedirectToAction("Index"); } // Обновляем comp.Name = model.Name; comp.LegalType = model.LegalType; comp.Email = model.Email; comp.Phone = model.Phone; comp.City = model.City; comp.Address = model.Address; comp.ContactPerson = model.ContactPerson; comp.INN = model.INN; comp.OGRN = model.OGRN; comp.KPP = model.KPP; comp.OKPO = model.OKPO; comp.ContactPhone = model.ContactPhone; comp.Fax = model.Fax; comp.DirectorFIO = model.DirectorFIO; comp.LegalAddress = model.LegalAddress; comp.LegalDocument = model.LegalDocument; comp.AccountRNumber = model.AccountRNumber; comp.AccountKNumber = model.AccountKNumber; comp.AccountBankBIK = model.AccountBankBIK; comp.AccountBankName = model.AccountBankName; comp.PassportNumber = model.PassportNumber; comp.PassportIssuedBy = model.PassportIssuedBy; comp.PassportIssueDate = model.PassportIssueDate; comp.PassportDivisionCode = model.PassportDivisionCode; comp.Status = model.Status; comp.PersonalDiscount = model.PersonalDiscount; if (logoPath != null) { comp.Logo = logoPath; } comp.DateModified = DateTime.Now; rep.SubmitChanges(); ShowSuccess(string.Format("Изменения в компании {0} успешно сохранены", comp.Name)); } return RedirectToAction("Index"); }
/// <summary> /// Получает цену на позицию с учетом накрутки системы, а так же персональной скидки компании /// </summary> /// <param name="company">Компания</param> /// <param name="companyMargin">Отобразить цену с учетом накрутки компании</param> /// <returns></returns> public decimal GetPrice(Company company, bool companyMargin = false) { var margin = CalculateMargin(); var price = (VendorPrice.HasValue ? VendorPrice.Value : 0) + margin; if (companyMargin) { price -= price*company.PriceMargin/100; } return price; }