//[ValidationActionFilter]
        public string Create([FromBody] CreateCarouselModelNoFile model)
        {
            if (ModelState.IsValid)
            {
                int seq = 0;
                if (model.Sequence == 0)
                {
                    var record = db.Carousel.FirstOrDefault(c => !c.IsDeleted);

                    if (record != null)
                    {
                        seq = db.Carousel.Where(c => !c.IsDeleted).Max(x => x.Sequence);
                    }
                }

                seq++;

                var carousel = new Carousel
                {
                    Title        = model.Title,
                    Description  = model.Description,
                    Sequence     = seq,
                    Display      = (model.Display) ? true : false,
                    DisplayDate  = model.DisplayDate,
                    IsDeleted    = false,
                    CreatedDate  = DateTime.Now,
                    CreatedBy    = model.CreatedBy,
                    TextLocation = (int)model.TextLocation,
                    FreeTextArea = model.FreeTextArea
                };

                db.Carousel.Add(carousel);
                db.SaveChanges();

                //files 1
                foreach (var fileid in model.CoverFilesId)
                {
                    var coverfile = new CarouselFile
                    {
                        FileId   = fileid,
                        ParentId = carousel.Id
                    };

                    db.CarouselFile.Add(coverfile);
                }

                // modify carousel by adding ref no based on year, month and new ID (Survey= SVP & SVT)
                var refno = "CRS/" + DateTime.Now.ToString("yyMM");
                refno         += "/" + carousel.Id.ToString("D4");
                carousel.RefNo = refno;

                db.Entry(carousel).State = EntityState.Modified;
                db.SaveChanges();

                return(carousel.Id.ToString() + "|" + model.Title);
            }
            return("");
        }
        public async Task <ActionResult> Create(CreateCarouselModel model, string Submittype)
        {
            if (model.CoverPictures.Count() == 0 && model.CoverPictureFiles.Count() == 0)
            {
                ModelState.AddModelError("CoverPictures", "Please upload an image");
            }
            else
            {
                //validate file
                foreach (var file in model.CoverPictureFiles)
                {
                    if (!FileMethod.IsValidType(file, filter_imgs))
                    {
                        ModelState.AddModelError("CoverPictures", Language.Carousel.ValidAttachment);
                        break;
                    }
                }
            }

            if (ModelState.IsValid)
            {
                var apimodel = new CreateCarouselModelNoFile
                {
                    Title         = model.Title,
                    Description   = model.Description,
                    Display       = model.Display,
                    DisplayDate   = model.DisplayDate,
                    TextLocation  = model.TextLocation,
                    FreeTextArea  = model.FreeTextArea,
                    CoverPictures = model.CoverPictures,
                    CreatedBy     = model.CreatedBy,
                    CreatedDate   = model.CreatedDate
                };

                if (model.CoverPictureFiles.Count() > 0)
                {
                    var files = await FileMethod.UploadFile(model.CoverPictureFiles.ToList(), CurrentUser.UserId, "carousel");

                    if (files != null)
                    {
                        apimodel.CoverFilesId = files.Select(f => f.Id).ToList();
                    }
                }

                var response = await WepApiMethod.SendApiAsync <string>(HttpVerbs.Post, $"Carousels/Carousel/Create", apimodel);

                if (response.isSuccess)
                {
                    string[] resparray = response.Data.Split('|');
                    string   newid     = resparray[0];
                    string   title     = resparray[1];

                    if ((model.CoverPictureFiles.Count() > 0))
                    {
                        await UploadImageFiles(int.Parse(newid), model.CoverPictureFiles.First());
                    }

                    await LogActivity(Modules.CarouselManagement, "Create New Carousel: " + title);

                    if (Submittype == "Save")
                    {
                        TempData["SuccessMessage"] = "New Carousel titled " + title + " created successfully and saved as draft.";

                        return(RedirectToAction("Index", "Carousel", new { area = "CarouselManagement" }));
                    }
                    else
                    {
                        return(RedirectToAction("Details", "Carousel", new { area = "CarouselManagement", @id = newid }));
                    }
                }
                else
                {
                    TempData["SuccessMessage"] = "Failed to create new Carousel.";

                    return(RedirectToAction("Index", "Carousel", new { area = "CarouselManagement" }));
                }
            }

            return(View(model));
        }