Exemplo n.º 1
0
        public CatalogueView GetCatalogue(int catalogueId, out string message)
        {
            CatalogueView result = new CatalogueView();

            message = null;
            try
            {
                using (var db = new SqlConnection(conn))
                {
                    var    parameters = new DynamicParameters();
                    string SqlQuery   = "SELECT top 1 * FROM v_CatalogueInfo WHERE Id=@catalogueId";
                    if (catalogueId >= 0)
                    {
                        parameters.Add("@catalogueId", catalogueId);
                        result = db.Query <CatalogueView>(SqlQuery, parameters).FirstOrDefault();
                    }
                    else
                    {
                        message = String.Format(StaticResources.Resources.SYSTEM_ERROR_THE_PARAMETER_LARGE_ZERO, catalogueId);
                    }
                }
            }
            catch (Exception ex)
            {
                string subject = "Error " + SiteSetting.SiteName + " at GetCatalogue at CatalogueRepo at Model.Repository";
                message += subject + StringHelper.Parameters2ErrorString(ex, catalogueId);
            }
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create a new catalogue
        /// </summary>
        /// <param name="model"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public CatalogueView CreateCatalogue(CatalogueView model, out string message)
        {
            CatalogueView result = new CatalogueView();

            message = null;
            Catalogue catalogue = new Catalogue();

            try
            {
                if (model != null)
                {
                    ///site info
                    ///
                    catalogue.SiteName = model.SiteName;
                    catalogue.SiteUrl  = model.SiteUrl;
                    catalogue.Name     = model.CatalogueName;
                    ///email
                    catalogue.EmailSite  = model.EmailSite;
                    catalogue.EmailAdmin = model.EmailAdmin;
                    ///address info
                    catalogue.Address = model.Address;
                    catalogue.Phones  = model.Phones;
                    ///seo
                    catalogue.MetaKeywords     = model.MetaKeywords;
                    catalogue.MetaDescriptions = model.MetaDescriptions;
                    catalogue.Facebook         = model.Facebook;
                    catalogue.Twitter          = model.Twitter;
                    catalogue.Youtube          = model.Youtube;
                    catalogue.GooglePlus       = model.GooglePlus;
                    //system
                    catalogue.CreatedBy    = model.CreatedById;
                    catalogue.CreatedDate  = DateTime.Now;
                    catalogue.ModifiedDate = DateTime.Now;
                    catalogue.ModifiedBy   = model.ModifiedById;
                    catalogue.Status       = model.Status;

                    catalogue = entities.Catalogues.Add(catalogue);
                    if (entities.SaveChanges() > 0)
                    {
                        result = this.GetCatalogue(catalogue.Id, out message);
                    }
                    else
                    {
                        message = StaticResources.Resources.SYSTEM_ERROR_THE_UPDATING_WEBSITE_CONFI_HAS_BEEN_FINISHED;
                    }
                }
                else
                {
                    message = StaticResources.Resources.MSG_THE_CATEGORY_HAS_CREATED_UNSUCCESSFULLY;
                }
            }
            catch (Exception ex)
            {
                string subject = "Error " + SiteSetting.SiteName + " at CreateCatalogue at CatalogueRepo at Model.Repository. ";
                message += subject + StringHelper.Parameters2ErrorString(ex, model.Id);
            }

            return(result);
        }
Exemplo n.º 3
0
        public ActionResult SiteConfig(CatalogueView model)
        {
            CatalogueView remodel      = new CatalogueView();
            var           actionStatus = new ActionResultHelper();

            actionStatus.ActionStatus = ResultSubmit.failed;
            string errorString = "";
            string message     = "";
            bool   IsValid     = true;

            //load site configtion
            if (ModelState.IsValid)
            {
                model.ModifiedById = 2;
                model.Id           = SiteConfiguration.CatalogueId;

                remodel = _catalogueRepo.UpdateCatalogue(model, out message);
                //return RedirectToAction("SiteConfig");
                if (String.IsNullOrWhiteSpace(message))
                {
                    actionStatus.ErrorReason  = String.Format(SiteResource.HTML_ALERT_SUCCESS, SiteResource.MSG_THE_SITE_CONFIGUARATION_HAS_BEEN_UPDATED_SUCCESSFULLY);
                    actionStatus.ActionStatus = ResultSubmit.success;
                    Session["ACTION_STATUS"]  = actionStatus;
                    return(View(remodel));
                }
                else
                {
                    IsValid     = false;
                    errorString = message;
                    goto actionError;
                }
            }
            else
            {
                IsValid = false;
                foreach (var item in ModelState.Values)
                {
                    if (item.Errors.Count() > 0)
                    {
                        var errorItems = item.Errors.Where(f => !String.IsNullOrWhiteSpace(f.ErrorMessage)).ToList();
                        foreach (var erroritem in errorItems)
                        {
                            errorString += "<br />" + erroritem.ErrorMessage;
                        }
                    }
                }
                goto actionError;
            }

actionError:
            if (!IsValid)
            {
                actionStatus.ErrorReason = String.Format(SiteResource.HTML_ALERT_ERROR, SiteResource.MSG_ERROR_ENTER_DATA_FOR_FORM + errorString);
                Session["ACTION_STATUS"] = actionStatus;
            }
            return(RedirectToAction("SiteConfig"));
        }
Exemplo n.º 4
0
        public ActionResult Create()
        {
            //load site configtion
            var model = new CatalogueView();

            ViewBag.Title  = "Tạo catalog mới";
            ViewBag.Action = "Create";
            return(View("Edit", model));
        }
Exemplo n.º 5
0
        public ActionResult Edit(CatalogueView model, string saveclose, string savenew)
        {
            CatalogueView remodel      = new CatalogueView();
            var           actionStatus = new ActionResultHelper();

            actionStatus.ActionStatus = ResultSubmit.failed;
            string errorString = "";
            string message     = "";
            bool   IsValid     = true;

            if (ModelState.IsValid)
            {
                model.ModifiedById = CurrentUser.ID;
                remodel            = _catalogueRepo.UpdateCatalogue(model, out message);
                if (remodel != null && String.IsNullOrWhiteSpace(message))
                {
                    actionStatus.ErrorReason  = String.Format(SiteResource.HTML_ALERT_SUCCESS, Resources.MSG_THE_SITE_CONFIGUARATION_HAS_BEEN_UPDATED_SUCCESSFULLY);
                    actionStatus.ActionStatus = ResultSubmit.success;
                    Session["ACTION_STATUS"]  = actionStatus;
                    if (!String.IsNullOrEmpty(saveclose))
                    {
                        return(RedirectToAction("Index"));
                    }
                    else if (!String.IsNullOrWhiteSpace(savenew))
                    {
                        return(RedirectToAction("Create"));
                    }
                    else
                    {
                        return(RedirectToAction("Edit", new { Id = remodel.Id }));
                    }
                }
                else
                {
                    IsValid     = false;
                    errorString = Resources.MSG_THE_SITE_CONFIGUARATION_HAS_BEEN_UPDATED_UNSUCCESSFULLY;
                    goto actionError;
                }
            }

actionError:
            if (!IsValid)
            {
                actionStatus.ErrorReason = String.Format(SiteResource.HTML_ALERT_ERROR, SiteResource.MSG_ERROR_ENTER_DATA_FOR_FORM + errorString);
                Session["ACTION_STATUS"] = actionStatus;
            }

            return(View(model));
        }
Exemplo n.º 6
0
        public ActionResult Create(CatalogueView model, string saveclose = "", string savenew = "")
        {
            var actionStatus = new ActionResultHelper();

            actionStatus.ActionStatus = ResultSubmit.failed;
            string        message = "";
            CatalogueView result  = new CatalogueView();

            if (ModelState.IsValid)
            {
                model.CreatedById  = CurrentUser.UserID;
                model.ModifiedById = CurrentUser.UserID;
                result             = _catalogueRepo.CreateCatalogue(model, out message);

                if (result != null && result.Id > 0)
                {
                    actionStatus.ErrorReason  = String.Format(SiteResource.HTML_ALERT_SUCCESS, Resources.MSG_THE_CATEGORY_HAS_CREATED_SUCCESSFULLY);
                    actionStatus.ActionStatus = ResultSubmit.success;
                    Session["ACTION_STATUS"]  = actionStatus;

                    if (!String.IsNullOrWhiteSpace(saveclose))
                    {
                        return(RedirectToAction("Index"));
                    }
                    else if (!String.IsNullOrWhiteSpace(savenew))
                    {
                        return(RedirectToAction("Create"));
                    }
                    else
                    {
                        return(RedirectToAction("Edit", new { id = result.Id }));
                    }
                }
                else
                {
                    ModelState.AddModelError("", Resources.MSG_THE_CATEGORY_HAS_CREATED_UNSUCCESSFULLY);
                }
            }

            //load site configtion
            ViewBag.Title  = "Tạo catalog mới";
            ViewBag.Action = "Create";
            return(View("Edit", model));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Update Catalogue
        /// </summary>
        /// <param name="model"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public CatalogueView UpdateCatalogue(CatalogueView model, out string message)
        {
            CatalogueView result = new CatalogueView();

            message = null;
            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <v_CatalogueInfo, CatalogueView>();
            });
            IMapper mapper = config.CreateMapper();

            try
            {
                using (var entities = new Entities())
                {
                    var catalogue = entities.Catalogues.SingleOrDefault(s => s.Id == model.Id);

                    if (catalogue == null)
                    {
                        message = StaticResources.Resources.MSG_THE_CATEGORY_HAS_NOT_FOUND;
                        return(null);
                    }

                    ///site info
                    catalogue.Name     = model.CatalogueName;
                    catalogue.SiteName = model.SiteName;
                    catalogue.SiteUrl  = model.SiteUrl;
                    ///email
                    catalogue.EmailSite  = model.EmailSite;
                    catalogue.EmailAdmin = model.EmailAdmin;
                    ///address info
                    catalogue.Address = model.Address;
                    catalogue.Phones  = model.Phones;
                    ///seo
                    catalogue.MetaKeywords     = model.MetaKeywords;
                    catalogue.MetaDescriptions = model.MetaDescriptions;
                    catalogue.Facebook         = model.Facebook;
                    catalogue.Twitter          = model.Twitter;
                    catalogue.Youtube          = model.Youtube;
                    catalogue.GooglePlus       = model.GooglePlus;
                    //system
                    catalogue.Status       = model.Status;
                    catalogue.ModifiedDate = DateTime.Now;
                    catalogue.ModifiedBy   = model.ModifiedById;

                    if (catalogue != null && entities.SaveChanges() > 0)
                    {
                        v_CatalogueInfo catalogueInfo = entities.v_CatalogueInfo.Where(w => w.Id == catalogue.Id).FirstOrDefault();
                        result = mapper.Map <v_CatalogueInfo, CatalogueView>(catalogueInfo);
                    }
                    else
                    {
                        message = StaticResources.Resources.SYSTEM_ERROR_THE_UPDATING_WEBSITE_CONFI_HAS_BEEN_FINISHED;
                    }
                }
            }
            catch (Exception ex)
            {
                string subject = "Error " + SiteSetting.SiteName + " at UpdateCatalogue at CatalogueRepo at Model.Repository. ";
                message += subject + StringHelper.Parameters2ErrorString(ex, model.Id);
            }

            return(result);
        }