Exemplo n.º 1
0
        public bool UpdateCategory(MS_Category category)
        {
            string sql = " Update MS_Category set CategoryName=@CategoryName,CategoryCode=@CategoryCode,OrganizationId=@OrganizationId," +
                         " LastUpdatedBy=@LastUpdatedBy,LastUpdatedDate=@LastUpdatedDate" +
                         " where CategoryId=@CategoryId";

            using (var db = DbHelper.GetDBConnection())
            {
                using (var trsn = new TransactionScope())
                {
                    //db.Execute(sql);
                    var lst = db.Execute(sql, category);
                    trsn.Complete();
                    db.Close();
                    if (lst > 0)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public bool InsertCategory(MS_Category category)
        {
            string sql = " Insert into  MS_Category (CategoryName,CategoryCode,OrganizationId,EnteredBy,EnteredDate," +
                         " LastUpdatedBy,LastUpdatedDate,IsDeleted,DeletedDate,DeletedBy) " +
                         " values " +
                         "(@CategoryName,@CategoryCode,@OrganizationId,@EnteredBy,@EnteredDate," +
                         "0,null,0,null,0)";

            using (var db = DbHelper.GetDBConnection())
            {
                using (var trsn = new TransactionScope())
                {
                    //db.Execute(sql);
                    var lst = db.Execute(sql, category);
                    trsn.Complete();
                    db.Close();
                    if (lst > 0)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
        }
 // GET: Category/Edit/5
 public ActionResult Edit(int? id)
 {
     if (id == null)
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     MS_Category mS_Category = db.GetCategoryById((int)id);
     if (mS_Category == null)
     {
         return HttpNotFound();
     }
     ViewBag.OrganizationId = new SelectList(ddl.GetOrganizationList(), "Id", "Name", mS_Category.OrganizationId);
     return View(mS_Category);
 }
 public ActionResult Edit(FormCollection frm)
 {
     var ses = sesrepo.GetSessionById((User as CustomPrincipal).UserId);
     int orgid = ses.OrganizationId;
     MS_Category mS_Category = db.GetCategoryById(Convert.ToInt32(frm["CategoryId"]));
     mS_Category.CategoryName = frm["CategoryName"];
     mS_Category.CategoryCode = frm["CategoryCode"];
     mS_Category.OrganizationId = orgid;// Convert.ToInt32(frm["OrganizationId"]);
     mS_Category.LastUpdatedBy = (User as CustomPrincipal).UserId;
     mS_Category.LastUpdatedDate = DateTime.Now;
     if (ModelState.IsValid)
     {
         db.UpdateCategory(mS_Category);
         return RedirectToAction("Index");
     }
     ViewBag.OrganizationId = new SelectList(ddl.GetOrganizationList(), "Id", "Name", mS_Category.OrganizationId);
     return View(mS_Category);
 }
        public void CreateMsCategory(CreateCategoryInputDto input)
        {
            Logger.Info("CreateMsCategory() - Started.");
            Logger.DebugFormat("CreateMsCategory() - Start checking before insert Category. Parameters sent:{0}" +
                               "categoryCode = {1}{0}" +
                               "categoryName = {2}{0}"
                               , Environment.NewLine, input.categoryCode, input.categoryName);

            bool checkCategory = (from A in _msCategoryRepo.GetAll()
                                  where A.categoryCode == input.categoryCode ||
                                  A.categoryName == input.categoryName
                                  select A).Any();

            Logger.DebugFormat("CreateMsCategory() - Ended checking before insert Category. Result = {0}", checkCategory);

            if (!checkCategory)
            {
                var createMsCategory = new MS_Category
                {
                    categoryName  = input.categoryName,
                    categoryCode  = input.categoryCode,
                    projectField  = "-", //hardcode for not null field
                    areaField     = "-", //hardcode for not null field
                    categoryField = "-", //hardcode for not null field
                    clusterField  = "-", //hardcode for not null field
                    productField  = "-", //hardcode for not null field
                    detailField   = "-", //hardcode for not null field
                    zoningField   = "-", //hardcode for not null field
                    facingField   = "-", //hardcode for not null field
                    roadField     = "-", //hardcode for not null field
                    kavNoField    = "-"
                };


                try
                {
                    Logger.DebugFormat("CreateMsCategory() - Start insert Category. Parameters sent:{0}" +
                                       "categoryName = {1}{0}" +
                                       "categoryCode = {2}{0}" +
                                       "projectField = {3}{0}" +
                                       "areaField = {4}{0}" +
                                       "categoryField = {5}{0}" +
                                       "clusterField = {6}{0}" +
                                       "productField = {7}{0}" +
                                       "detailField = {8}{0}" +
                                       "zoningField = {9}{0}" +
                                       "facingField = {10}{0}" +
                                       "roadField = {11}{0}" +
                                       "kavNoField = {12}{0}"
                                       , Environment.NewLine, input.categoryName, input.categoryCode, "-", "-", "-", "-", "-"
                                       , "-", "-", "-", "-", "-");

                    _msCategoryRepo.Insert(createMsCategory);
                    CurrentUnitOfWork.SaveChanges();

                    Logger.DebugFormat("CreateMsCategory() - Ended insert Category.");
                }

                /*catch (DbEntityValidationException ex)
                 * {
                 *  var errorMessages = ex.EntityValidationErrors
                 *      .SelectMany(x => x.ValidationErrors)
                 *      .Select(x => x.ErrorMessage);
                 *  string fullErrorMessage = string.Join("; ", errorMessages);
                 *  string exceptionMessage = string.Concat("Validation Error: ", fullErrorMessage);
                 *  Logger.ErrorFormat("CreateMsCategory() - ERROR DbEntityValidationException. Result = {0}", exceptionMessage);
                 *  throw new UserFriendlyException(exceptionMessage);
                 * }*/
                catch (DataException ex)
                {
                    Logger.ErrorFormat("CreateMsCategory() - ERROR DataException. Result = {0}", ex.Message);
                    throw new UserFriendlyException("Db Error: " + ex.Message);
                }
                catch (Exception ex)
                {
                    Logger.ErrorFormat("CreateMsCategory() - ERROR Exception. Result = {0}", ex.Message);
                    throw new UserFriendlyException("Error: " + ex.Message);
                }
            }
            else
            {
                Logger.ErrorFormat("CreateMsCategory() - ERROR Exception.", "Category Code or Category Name Already Exist !");
                throw new UserFriendlyException("Category Code or Category Name Already Exist !");
            }
            Logger.Info("CreateMsCategory() - Finished.");
        }