Ejemplo n.º 1
0
 /// <summary>
 /// Peroform the edit operation
 /// </summary>
 /// <param name="catalogueIdEdit">Id of catalogue for edit</param>
 /// <returns>ActionResult</returns>
 public ActionResult EditCatalogue(Guid? catalogueIdEdit)
 {
     Catalogue catalogue = CatalogueBusiness.GetCatalogueCategory(catalogueIdEdit.GetValueOrDefault());
     CatalogueModel model = new CatalogueModel
     {
         BusinessApplicationId = catalogue.BusinessApplicationId,
         CatalogueCategoryName = catalogue.CatalogueCategoryName,
         CatalogueId = catalogue.CatalogueId,
         ScreenOpenMode = ScreenOpenMode.Edit
     };
     return View("Catalogue", model);
 }
Ejemplo n.º 2
0
 public ActionResult SaveCatalogue(CatalogueModel model)
 {
     if (model.BusinessApplicationId == null)
     {
         model.Errors.Add("Please select a business application");
     }
     if (string.IsNullOrEmpty(model.CatalogueCategoryName))
     {
         model.Errors.Add("Please write a name for the catalogue");
     }
     if (!model.HasErrors)
     {
         model = CatalogueBusiness.SaveCategoryCatalogue(model, UserName);
         return Json(model);
     }
     else
     {
         return Json(model);
     }
 }
Ejemplo n.º 3
0
        private static void UpdateCatalogueCategory(CatalogueModel model, string userName, bool categoryExist, VestalisEntities context)
        {
            //get the current catalogue to edit
            Catalogue CatalogueModified = context.Catalogues
            .FirstOrDefault(data => data.IsDeleted == false && data.CatalogueId == model.CatalogueId);

            if (CatalogueModified != null && CatalogueModified.CatalogueCategoryName == model.CatalogueCategoryName)
            {
                //set fields to modify the information
                CatalogueModified.BusinessApplicationId = model.BusinessApplicationId;
                CatalogueModified.CatalogueCategoryName = model.CatalogueCategoryName;
                //set auditory fields
                CatalogueModified.ModificationBy = userName;
                CatalogueModified.ModificationDate = DateTime.UtcNow;
                //save changes
                context.SaveChanges();
            }
            else if (CatalogueModified != null && CatalogueModified.CatalogueCategoryName != model.CatalogueCategoryName)
            {
                if (!categoryExist)
                {
                    //set fields to modify the information
                    CatalogueModified.BusinessApplicationId = model.BusinessApplicationId;
                    CatalogueModified.CatalogueCategoryName = model.CatalogueCategoryName;
                    //set auditory fields
                    CatalogueModified.ModificationBy = userName;
                    CatalogueModified.ModificationDate = DateTime.UtcNow;
                    //save changes
                    context.SaveChanges();
                }
                else
                {
                    model.Errors.Add(LanguageResource.CatalogueCategoryExists);
                }
            }
        }
Ejemplo n.º 4
0
 public ActionResult NewCatalogue()
 {
     CatalogueModel model = new CatalogueModel();
     model.ScreenOpenMode = ScreenOpenMode.Add;
     return View("Catalogue", model);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Save a new catalogue in the database
        /// </summary>
        /// <param name="model">Catalogue model</param>
        /// <param name="userName">Name of logged user</param>
        public static CatalogueModel SaveCategoryCatalogue(CatalogueModel model, string userName)
        {
            bool categoryExist = false;
            using (VestalisEntities context = new VestalisEntities())
            {

                categoryExist = context.Catalogues
                    .Any(data => data.IsDeleted == false && data.BusinessApplicationId == model.BusinessApplicationId
                        && data.CatalogueCategoryName == model.CatalogueCategoryName);

                //if the entity don't have a catalogue id, the system will perform insert operation
                //otherwise, the system will perform edit operation
                if (model.CatalogueId == Guid.Empty)
                {
                    if (!categoryExist)
                    {
                        Catalogue catalogue = new Catalogue
                        {
                            BusinessApplicationId = model.BusinessApplicationId,
                            CatalogueCategoryName = model.CatalogueCategoryName,
                        };
                        //set auditory fields
                        catalogue.CreationBy = userName;
                        catalogue.CreationDate = DateTime.UtcNow;
                        context.Catalogues.AddObject(catalogue);

                        //save changes
                        context.SaveChanges();
                        model.CatalogueId = catalogue.CatalogueId;
                    }
                    else
                    {
                        model.Errors.Add(LanguageResource.CatalogueCategoryExists);
                    }
                }
                else
                {
                    UpdateCatalogueCategory(model, userName, categoryExist, context);
                }

            }
            return model;
        }