예제 #1
0
        public ActionResult AddTranslationResource(Resources model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    TempData["ResultSuccess"] = "Succes in adding new resource!";

                    using (var dataContext = new MultiLanguageModel())
                        using (var transaction = dataContext.Database.BeginTransaction())
                        {
                            var tblCon = new tblContext();
                            tblCon.Context     = model.Context;
                            tblCon.UserName    = User.Identity.Name;
                            tblCon.DateChanged = DateTime.Now;
                            tblCon.DateCreated = DateTime.Now;
                            db.tblContext.Add(tblCon);
                            db.SaveChanges();

                            var IdCont = (from tblContext in db.tblContext
                                          orderby tblContext.DateCreated descending
                                          select tblContext).First();

                            var tblRes = new tblResources()
                            {
                                IdResource  = model.IdResource,
                                IdLanguage  = Convert.ToInt32(model.IdLanguage),
                                IdContext   = IdCont.IdContext,
                                UserName    = User.Identity.Name,
                                DateChanged = DateTime.Now,
                                DateCreated = DateTime.Now
                            };

                            dataContext.Set <tblResources>().Add(tblRes);
                            dataContext.Database.ExecuteSqlCommand("SET IDENTITY_INSERT tblResources ON");
                            dataContext.SaveChanges();
                            dataContext.Database.ExecuteSqlCommand("SET IDENTITY_INSERT tblResources OFF");

                            transaction.Commit();
                        }
                    return(RedirectToAction("AddTranslationResource", new { id = model.IdResource }));
                }
                catch (Exception ex)
                {
                    SendExceptionToAdmin(ex.ToString());
                }
            }

            else
            {
                TempData["ResultError"] = "Error in adding new translation!";
            }



            return(RedirectToAction("AddTranslationResource"));
        }
예제 #2
0
        public ActionResult AddNewStaticText(StaticResources model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    using (var dataContext = new MultiLanguageModel())
                        using (var transaction = dataContext.Database.BeginTransaction())
                        {
                            var tblCon = new tblStaticTexts();
                            tblCon.StaticText  = model.Text;
                            tblCon.UserName    = User.Identity.Name;
                            tblCon.DateChanged = DateTime.Now;
                            tblCon.DateCreated = DateTime.Now;

                            db.tblStaticTexts.Add(tblCon);
                            db.SaveChanges();

                            var IdCont = (from tblStaticTexts in db.tblStaticTexts
                                          orderby tblStaticTexts.DateCreated descending
                                          select tblStaticTexts).First();
                            int intIdt = db.tblStaticResources.Max(u => u.IdStatic);
                            var tblRes = new tblStaticResources()
                            {
                                IdStatic     = intIdt + 1,
                                IdLanguage   = Convert.ToInt32(model.IdLanguage),
                                IdStaticText = IdCont.IdStaticText,
                                Description  = model.Description,
                                UserName     = User.Identity.Name,
                                DateChanged  = DateTime.Now,
                                DateCreated  = DateTime.Now
                            };

                            dataContext.Set <tblStaticResources>().Add(tblRes);
                            dataContext.Database.ExecuteSqlCommand("SET IDENTITY_INSERT tblStaticResources ON");
                            dataContext.SaveChanges();
                            dataContext.Database.ExecuteSqlCommand("SET IDENTITY_INSERT tblStaticResources OFF");

                            transaction.Commit();
                            TempData["ResultSuccess"] = "Succes in adding new resource!";
                        }
                    return(RedirectToAction("ViewAllStaticTexts"));
                }
                catch (Exception ex)
                {
                    SendExceptionToAdmin(ex.ToString());
                }
            }
            else
            {
                TempData["ResultError"] = "Error in adding new translation!";
            }

            model.IdLanguages = new SelectList(db.tblLanguages, "IdLanguage", "Language");
            return(View(model));
        }