예제 #1
0
        public JsonResult CreateAddressAjax(Address modelAddress)
        {
            if (!Request.IsAjaxRequest())
            {
                TempData["ResultError"] = "Грешка в добавяне на адрес!";
                return(Json(false));
            }
            if (!ModelState.IsValid)
            {
                TempData["ResultError"] = "Грешка в добавяне на адрес!";
                return(Json(false));
            }

            using (var context = new AkcetModel())
            {
                var address = new Address();
                address              = modelAddress;
                address.DateCreated  = DateTime.Now;
                address.DateModified = DateTime.Now;
                address.UserName     = User.Identity.Name;
                address.UserID       = User.Identity.GetUserId();

                context.Addresses.Add(address);

                context.SaveChanges();

                TempData["ResultSuccess"] = "Успешно добавихте адрес!";

                return(Json(new { id = address.IdAddress, value = address.StreetName }));
            }
        }
예제 #2
0
        public JsonResult CreateInvoiceAjax(string Companies, FakturiTemp Fakturi)
        {
            if (Companies == "0")
            {
                return(Json(false));
            }

            if (String.IsNullOrWhiteSpace(Fakturi.InvoiceDate))
            {
                return(Json(false));
            }

            if (String.IsNullOrWhiteSpace(Fakturi.InvoiceEndDate))
            {
                return(Json(false));
            }

            Fakturi.CompanyID = Int32.Parse(Companies);

            var userId = User.Identity.GetUserId();

            using (var context = new AkcetModel())
            {
                var temp = new List <ProductInvoiceTemp>();
                Fakturi.ProductInvoiceTemps = temp;
                Fakturi.UserId       = userId;
                Fakturi.DateCreated  = DateTime.Now;
                Fakturi.DateModified = DateTime.Now;
                Fakturi.UserName     = User.Identity.Name;
                context.FakturiTemps.Add(Fakturi);
                context.SaveChanges();
            }
            return(Json(Fakturi));
        }
예제 #3
0
        public ActionResult CreateCompanyAjax([Bind(Exclude = "UserId", Include = "CompanyID,UserId,IdAddress,CompanyName,CompanyMol,DdsNumber,CompanyDescription,CompanyPhone,IsPrimary,DateCreated,DateModified")] Company company)
        {
            ModelState.Remove("UserId");

            if (!Request.IsAjaxRequest())
            {
                return(Json(false));
            }
            if (!ModelState.IsValid)
            {
                return(Json(false));
            }
            if (company.IdAddress == 0)
            {
                TempData["ResultError"] = "Не сте избрали адрес на фирмата!";
                return(Json(false));
            }
            using (var context = new AkcetModel())
            {
                company.DateCreated  = DateTime.Now;
                company.DateModified = DateTime.Now;
                company.UserId       = User.Identity.GetUserId();
                company.IsDeleted    = false;
                db.Companies.Add(company);
                db.SaveChanges();


                return(Json(new { id = company.CompanyID, value = company.CompanyName }));
            }
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Fakturi fakturi = dbAkcet.Fakturis.Find(id);

            foreach (var product in dbAkcet.ProductInvoices.Where(p => p.InvoiceID == id))
            {
                dbAkcet.ProductInvoices.Remove(product);
            }
            var counter    = Int32.Parse(fakturi.FakturaNumber.Split('-')[1]) + 1;
            var counterTbl = dbAkcet.Counters.Where(c => c.CounterValue == counter && c.UserID == fakturi.UserID).FirstOrDefault();

            // TODO: When invoice is deleted counter is still in max value
            dbAkcet.Fakturis.Remove(fakturi);
            dbAkcet.SaveChanges();
            return(RedirectToAction("Index"));
        }