コード例 #1
0
        public FileUpViewModel Insert(FileUpViewModel objEntity)
        {
            try
            {
                Database objDB = base.GetDatabase();
                // Create a suitable command type and add the required parameter.
                using (DbCommand sprocCmd = objDB.GetStoredProcCommand(SP_FileUpViewModelInsert))
                {
                    objDB.AddInParameter(sprocCmd, PARAM_FileName, DbType.String, objEntity.FileName);



                    objDB.AddOutParameter(sprocCmd, PARAM_Id, DbType.Int16, objEntity.Id);

                    objDB.AddOutParameter(sprocCmd, PARAM_Result, DbType.Int32, objEntity.Result);
                    objDB.ExecuteNonQuery(sprocCmd);
                    objEntity.Id     = Convert.ToInt32(objDB.GetParameterValue(sprocCmd, PARAM_Id));
                    objEntity.Result = Convert.ToInt32(objDB.GetParameterValue(sprocCmd, PARAM_Result));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
            }
            return(objEntity);
        }
コード例 #2
0
        public ActionResult Create(FileUpViewModel objEntity)
        {
            FileUpViewModel  objFileUpRepository = new FileUpViewModel();
            FileUpRepository objfileRepository   = new FileUpRepository();
            string           fileName            = string.Empty;

            if (ModelState.IsValid)
            {
                if (!string.IsNullOrEmpty(objEntity.UpFile.FileName))
                {
                    fileName           = Guid.NewGuid().ToString() + Path.GetExtension(objEntity.UpFile.FileName);
                    objEntity.FileName = fileName;
                }

                objfileRepository.Insert(objEntity);

                if (objEntity.Result == ResultFlags.Success.GetHashCode())
                {
                    //save image http://www.w3schools.com/aspnet/webpages_ref_helpers.asp


                    //file name
                    if (!string.IsNullOrEmpty(objEntity.UpFile.FileName))
                    {
                        string path = Path.Combine(Server.MapPath(ApplicationConstant.UPLOADED_EMPLOYER_LOGO_PATH), fileName);
                        // WebImage.Save()
                        objEntity.UpFile.SaveAs(path);
                    }
                    this.Flash("success", "Student Insert successfully ");
                    return(RedirectToAction("Index"));
                }

                else if (objEntity.Result == ResultFlags.Failure.GetHashCode())
                {
                    this.Flash("error", "Faild to Insert File");
                    return(RedirectToAction("Index"));
                }
                else if (objEntity.Result == ResultFlags.Duplicate.GetHashCode())
                {
                    this.Flash("warning", "File is Already Exist");
                    return(RedirectToAction("Index"));
                }
            }
            return(View(objEntity));
        }