public async Task AddUpdate(Common.Model.Competition request)
        {
            DIBZ.Common.Model.Competition competition = null;
            if (request.Id > 0)
            {
                competition = await GetCompetitionById(request.Id);

                competition.Name    = request.Name;
                competition.Title   = request.Title;
                competition.Content = request.Content;
                if (!String.IsNullOrEmpty(request.FileNewName))
                {
                    competition.FileOrignalName = request.FileOrignalName;
                    competition.FileNewName     = request.FileNewName;
                }
                competition.UpdatedTime = DateTime.Now;
                competition.IsActive    = request.IsActive;
            }
            else
            {
                competition = new DIBZ.Common.Model.Competition
                {
                    Name            = request.Name,
                    Title           = request.Title,
                    FileOrignalName = request.FileOrignalName,
                    FileNewName     = request.FileNewName,
                    CreatedTime     = DateTime.Now,
                    IsActive        = request.IsActive,
                };

                Db.Add(competition);
            }
            await Db.SaveAsync();
        }
        public async Task <ActionResult> AddUpdateContent(FormCollection formData, HttpPostedFileBase file)
        {
            var    serverPath      = Server.MapPath("~/Uploads");
            string fileNewName     = string.Empty;
            string fileOrignalName = string.Empty;
            int    isUploaded      = 0;

            if (file != null)
            {
                Random rnd          = new Random();
                int    rendomNumber = rnd.Next(52);
                string extension    = Path.GetExtension(file.FileName);
                var    filename     = Path.GetFileNameWithoutExtension(file.FileName);
                fileNewName     = filename + rendomNumber + extension;
                fileOrignalName = file.FileName;

                var fileSizeInMB = file.ContentLength / 1024;
                var savePath     = Path.Combine(serverPath, fileNewName.ToString());
                if (fileSizeInMB >= 1024 * 1.65)
                {
                    var originalFilePath = Path.Combine(serverPath, (fileNewName).ToString());
                    file.SaveAs(originalFilePath);
                    FileSaveHelper.ResizeTo(originalFilePath, 865, 500, savePath);
                    System.IO.File.Delete(originalFilePath);
                    isUploaded = 1;
                }
                else
                {
                    file.SaveAs(savePath);
                    isUploaded = 1;
                }
            }

            int id = Convert.ToInt32(formData["Id"]);
            var newsFeedLogicLogic = LogicContext.Create <CompetitionLogic>();

            DIBZ.Common.Model.Competition request = new Common.Model.Competition();
            request.Id      = id;
            request.Name    = formData["txtname"];
            request.Title   = formData["txttitle"];
            request.Content = formData["txtcontent"];
            if (isUploaded == 1)
            {
                request.FileNewName     = fileNewName;
                request.FileOrignalName = fileOrignalName;
            }
            else
            {
                request.FileNewName     = "";
                request.FileOrignalName = "";
            }
            var status = formData["status"];

            if (status == "1")
            {
                request.IsActive = true;
            }
            else
            {
                request.IsActive = false;
            }

            await newsFeedLogicLogic.AddUpdate(request);

            return(RedirectToAction("Index"));
        }