Beispiel #1
0
        public bool RegisterKompanija(RegisterKompanijaModel model, HttpPostedFileBase logo)
        {
            var kompanija = new Kompanii
            {
                KorisnickoIme = model.KorisnickoIme,
                Lozinka = model.Password,
                Mail = model.Email,
                NazivNaKompanija = model.Naziv,
                Telefon = model.Telefon
            };

            _db.Kompanii.Add(kompanija);
            _db.SaveChanges();

            //save the image if is provided
            if (logo != null)
            {
                string[] allowed = { ".jpg", ".jpeg", ".png", ".gif" };
                string extension = System.IO.Path.GetExtension(logo.FileName);

                if (allowed.Contains(extension.ToLower()))
                {
                    string CoverPath = "/Images/CompanyImages/Logos/"; //TODO: patekata treba da se zima od web.cofig
                    string imageName = "Logo_" + kompanija.IdKompanii + extension;
                    string NewLocation = HttpContext.Current.Server.MapPath("~") + CoverPath + imageName;
                    string tip = logo.GetType().ToString();
                    logo.SaveAs(NewLocation);
                    string path = CoverPath + imageName;

                    kompanija.LogoNaKompanija = path;
                    _db.SaveChanges();
                }
            }

            return true;
        }
        public ActionResult IzmeniProizvod(ProizvodViewModel proizvod, HttpPostedFileBase file, int id)
        {
            // System.IO.File.SetAttributes(Server.MapPath("~") + proizvod.SlikaNaProizvod, FileAttributes.Normal);
            if (!String.IsNullOrEmpty(proizvod.SlikaNaProizvod) && file != null)
            {
                System.IO.File.Delete(Server.MapPath("~") + proizvod.SlikaNaProizvod);
            }

            if (file != null)
            {
                string[] allowed = { ".jpg", ".jpeg", ".png", ".gif" };

                string extension = System.IO.Path.GetExtension(file.FileName);
                if (allowed.Contains(extension.ToLower()))
                {
                    long addition = DateTime.Now.GetTimestampSeconds();
                    string CoverPath = "/Images/UserImages/";
                    proizvod.SlikaNaProizvod = CoverPath + "Cover_" + proizvod.IdProizvodi + "_" + addition + extension;
                    string NewLocation = Server.MapPath("~") + proizvod.SlikaNaProizvod;
                    string tip = file.GetType().ToString();
                    file.SaveAs(NewLocation);
                }
            }
            model.IzmeniProizvod(proizvod);
            return RedirectToAction("PregledajProizvod", new { idProizvod = proizvod.IdProizvodi, idKategorija= proizvod.IdKategorii});
        }