Пример #1
0
        public ActionResult Edit(int id)
        {
            try
            {
                // USED IN POST METHOD
                ViewBag.IsSuccess = 0;
                ViewBag.Message   = "";
                fnSetProperties();

                COrnamentsPosition     ornamentsPosition         = CFOrnamentsPosition.OrnamentsPositionDetailGetById(id);
                OrnamentsPositionModel objOrnamentsPositionModel = new OrnamentsPositionModel(ornamentsPosition);
                return(View(objOrnamentsPositionModel));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", "Error", new { Message = ex.Message, InnerException = ex.InnerException }));
            }
        }
        public static CSQLResult OrnamentsPositionDetailSave(OrnamentsPositionModel ornamentsPositionModel, int ModifiedBy, int ModifiedSourceCode)
        {
            CSQLResult oResult = new CSQLResult();

            try
            {
                CShared oDBShared = new CShared();

                string spParameter = ornamentsPositionModel.OrnamentPositionID + ","
                                     + ornamentsPositionModel.CategoryID + ", '"
                                     + ornamentsPositionModel.Name + "','"
                                     + ornamentsPositionModel.Description + "','"
                                     + ornamentsPositionModel.ImgPath + "',"
                                     + ModifiedBy + ","
                                     + ModifiedBy + ","
                                     + ModifiedSourceCode;

                DataSet dsOrnamentsPosition = oDBShared.GetDataSet("TOrnamentsPosition", "uspPositionDetailSave " + spParameter);

                using (DataTable dtOrnamentsPosition = dsOrnamentsPosition.Tables["TOrnamentsPosition"])
                {
                    if (dtOrnamentsPosition != null && dtOrnamentsPosition.Rows.Count > 0)
                    {
                        oResult.Success   = Convert.ToBoolean(dtOrnamentsPosition.Rows[0]["IsSuccess"]);
                        oResult.Exception = dtOrnamentsPosition.Rows[0]["ErrorSuccessMsg"].ToString();

                        if (oResult.Success)
                        {
                            // SET OTHER PARAMETER INFORMATION
                            //oResult.OtherParameter = dtCompany.Rows[0]["OrgPrjID"].ToString();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //oResult.Success = false;
                //oResult.WasSuccessful = 0;
                //oResult.Exception = ex.Message;

                throw ex;
            }
            return(oResult);
        }
Пример #3
0
        public ActionResult Add(OrnamentsPositionModel ornamentsPositionModel)
        {
            try
            {
                #region # SAVE IMAGE #

                string imgDBSavePath = ornamentsPositionModel.ImgPath;
                string sfileName     = "";
                string sFilePath     = "";

                if (ornamentsPositionModel.ImgFile != null)
                {
                    if (ornamentsPositionModel.ImgFile.ContentLength > 0)
                    {
                        string sFileExt = System.IO.Path.GetExtension(ornamentsPositionModel.ImgFile.FileName);

                        sfileName = ornamentsPositionModel.Name + "-" + DateTime.Now.ToString("ddMMyyHHmmss") + sFileExt;
                        sfileName = sfileName.Replace(" ", String.Empty);

                        imgDBSavePath = DirNamePositionImgSave + "/" + sfileName;

                        string CombineServerMapPath = ServerMapPath + DirNamePositionImgSave;
                        sFilePath = Server.MapPath(CombineServerMapPath);
                        sFilePath = sFilePath.Replace("\\" + PathRemoveString.ToString(), "");

                        if (!Directory.Exists(sFilePath))
                        {
                            DirectoryInfo di = Directory.CreateDirectory(sFilePath);
                        }
                        var path = Path.Combine(sFilePath, sfileName);
                        if (!String.IsNullOrEmpty(ornamentsPositionModel.ImgPath))
                        {
                            //SAVE FILE ON DISK
                            ornamentsPositionModel.ImgFile.SaveAs(path);
                            var RemoveOldImage = ornamentsPositionModel.ImgPath.Replace("/", "\\");
                            RemoveOldImage = sFilePath + RemoveOldImage.Replace(DirNamePositionImgSave, "");
                            //CHEK FILE IS EXIST ON DISK?
                            if (System.IO.File.Exists(RemoveOldImage))
                            {
                                //IF YES THEN SLEEP THREAD FOR 5 SEC AND DELETED EXISTING FILE
                                System.IO.File.Delete(RemoveOldImage);
                            }
                        }
                        else
                        {
                            //SAVE FILE ON DISK
                            ornamentsPositionModel.ImgFile.SaveAs(path);
                        }
                        // SET ORG LOGO PATH
                        ornamentsPositionModel.ImgPath = imgDBSavePath;
                    }
                }

                #endregion
                fnSetProperties();
                CSQLResult oResult = CFOrnamentsPosition.OrnamentsPositionDetailSave(ornamentsPositionModel, ModifiedBy, LoginTypeCode);

                if (oResult.Success)
                {
                    ViewBag.IsSuccess = 1;
                    ViewBag.Message   = oResult.Exception;
                }
                else
                {
                    ViewBag.IsSuccess = 0;
                    ViewBag.Message   = oResult.Exception;
                }
                return(View(ornamentsPositionModel));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", "Error", new { Message = ex.Message, InnerException = ex.InnerException, StackTrace = ex.StackTrace }));
            }
        }