示例#1
0
        public void InsertCategory(string name)
        {
            Category category = new Category();

            category.Name = name;

            entities.Category.Add(category);
            entities.SaveChanges();
        }
示例#2
0
        public JsonResult SaveFiles(HttpPostedFileBase file, int taskId)
        {
            string Message, fileName, actualFileName;

            Message = fileName = actualFileName = string.Empty;
            bool flag = false;

            if (file != null && file.ContentLength > 0)
            {
                actualFileName = file.FileName;
                fileName       = Guid.NewGuid() + Path.GetExtension(file.FileName);
                int size = file.ContentLength;

                try
                {
                    file.SaveAs(Server.MapPath("../UploadedFiles") + Guid.NewGuid() + "." + actualFileName.Split('.')[1]);

                    UploadFile f = new UploadFile
                    {
                        FileName = actualFileName,
                        FilePath = fileName,
                        TaskId   = taskId,
                        FileSize = size
                    };
                    using (AnyDoDBEntities1 dc = new AnyDoDBEntities1())
                    {
                        dc.UploadFile.Add(f);
                        dc.SaveChanges();
                        Message = "File uploaded successfully";
                        flag    = true;
                    }
                }
                catch (Exception)
                {
                    Message = "File upload failed! Please try again";
                }
            }
            return(new JsonResult {
                Data = new { Message = Message + taskId, Status = flag }
            });
        }