Beispiel #1
0
        public void AddTemplateToStore()
        {
            var obj = new Template();

            obj.Name = "MyTemplate";
            obj.Id   = 42;

            obj.TemplateProperties = new List <TemplateProperty>
            {
                new TemplateProperty
                {
                    key  = "logText",
                    type = "string"
                },

                new TemplateProperty
                {
                    key  = "timeStamp",
                    type = "datetime"
                }
            };

            var s = new TemplateService();

            var result = s.AddTemplate(obj);

            Assert.True(result == 42);
        }
Beispiel #2
0
        public ActionResult AddTemplate(string name)
        {
            string result      = string.Empty;
            var    currentUser = commonService.GetCurrentUser();

            if (currentUser == null)
            {
                result = "Login";
                return(Json(result));
            }
            string        fileName      = string.Empty;
            string        directoryPath = "";
            int           templateId    = 0;
            TemplateModel model         = new TemplateModel();

            try
            {
                if (!string.IsNullOrEmpty(name))
                {
                    model.Name      = name;
                    model.Status    = EnumStatus.Active.ToString();
                    model.CreatedAt = DateTime.Now;
                    model.CreatedBy = currentUser.UserId;
                    templateId      = templateService.AddTemplate(model).TemplateId;
                }

                #region Attachment Uploads
                IList <HttpPostedFileBase> files = new List <HttpPostedFileBase>();
                if (Request.Files != null)
                {
                    if (Request.Files.Count > 0)
                    {
                        var requestfile = Request.Files[0];
                        files.Add(requestfile);
                        fileName = Path.GetFileName(requestfile.FileName);

                        if (!string.IsNullOrEmpty(fileName))
                        {
                            directoryPath = Server.MapPath(templatePath + model.TemplateId + "//");

                            if (!Directory.Exists(directoryPath))
                            {
                                Directory.CreateDirectory(directoryPath);
                            }
                            var path = Path.Combine(directoryPath, fileName);
                            requestfile.SaveAs(path);

                            model.FileLocation = Path.Combine(model.TemplateId + "//" + fileName);
                        }
                    }
                }

                #endregion

                if (!string.IsNullOrEmpty(model.FileLocation) && templateId > 0)
                {
                    var template = templateService.GetTemplateById(templateId);
                    if (template != null)
                    {
                        template.FileLocation = model.FileLocation;
                        template.UpdatedAt    = DateTime.Now;
                        template.UpdatedBy    = currentUser.UserId;

                        templateService.UpdateTemplate(template);
                        result = "True";
                    }
                }
            }
            catch (Exception exception)
            {
                commonService.LogException(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, exception);
            }

            return(Json(result));
        }