public async Task <HttpResponseMessage> SaveMaterial()
        {
            TrainingMaterialViewModel model = new TrainingMaterialViewModel();
            // Send OK Response along with saved file names to the client.
            var provider = await Request.Content.ReadAsMultipartAsync <InMemoryMultipartFormDataStreamProvider>(new InMemoryMultipartFormDataStreamProvider());

            //access form data
            NameValueCollection formData = provider.FormData;

            model.YouTubeLink = formData["YouTubeLink"];
            model.TrainingId  = Convert.ToInt32(formData["TrainingId"]);
            //access files
            IList <HttpContent> files = provider.Files;

            if (files != null && files.Count > 0)
            {
                HttpContent file1        = files[0];
                var         thisFileName = file1.Headers.ContentDisposition.FileName.Trim('\"');

                model.FileName = thisFileName;

                string filename = String.Empty;
                Stream input    = await file1.ReadAsStreamAsync();

                string directoryName = String.Empty;
                string URL           = String.Empty;
                //string tempDocUrl = WebConfigurationManager.AppSettings["DocsUrl"];

                var path = HttpRuntime.AppDomainAppPath;
                directoryName = System.IO.Path.Combine(path, "TrainingDocuments");
                filename      = System.IO.Path.Combine(directoryName, thisFileName);

                string ext  = Path.GetExtension(filename);
                string guid = Guid.NewGuid().ToString();
                model.FileExtension = ext;
                filename            = System.IO.Path.Combine(directoryName, guid + ext);
                //Deletion exists file
                if (File.Exists(filename))
                {
                    File.Delete(filename);
                }
                Directory.CreateDirectory(@directoryName);
                using (Stream file = File.Create(filename))
                {
                    input.CopyTo(file);
                    //close file
                    file.Close();
                }
                model.FilePath = "~/TrainingDocuments/" + guid + ext;
            }
            this._ITrainingMaterialRepository.AddUpdateTrainingMaterial(model, base.UserId, base.OrganizationId);
            var response = Request.CreateResponse(HttpStatusCode.OK);

            return(response);


            // return "";
        }
        public int AddUpdateTrainingMaterial(TrainingMaterialViewModel model, int userid, int OrganizationId)
        {
            TrainingMaterial training = Mapper.Map <TrainingMaterialViewModel, TrainingMaterial>(model);

            training.OrganizationId = OrganizationId;
            if (model.TrainingMaterialId == 0)
            {
                base.Insert(training);
            }
            else
            {
                training = GetSingle(model.TrainingMaterialId, OrganizationId);
                base.Update(training);
            }
            this._unitOfWork.Save();
            return(training.TrainingMaterialId);
        }