Пример #1
0
        public JsonResult SaveFile(FileContentModel fileContent)
        {
            var fileName = DateTime.Now.Ticks + ".txt";

            if (!System.IO.Directory.Exists(Path.Combine(Server.MapPath("~/EricosnUpload"))))
            {
                System.IO.Directory.CreateDirectory(Path.Combine(Server.MapPath("~/EricosnUpload")));
            }
            var path        = Path.Combine(Server.MapPath("~/EricosnUpload/"), fileName);
            var returnValue = new JSONReturnValue();

            try
            {
                using (var file = new System.IO.StreamWriter(path))
                {
                    file.WriteLine(fileContent.Content);
                }
            }
            catch (Exception)
            {
                returnValue.Status  = false;
                returnValue.Message = "File Not Saved.";
            }
            try
            {
                var batMasterId = SaveBatMasterAndDetails(fileName, fileContent.Statements);
                if (batMasterId > 0)
                {
                    SendEmail(path, batMasterId);
                    returnValue.Status  = true;
                    returnValue.Message = "Mail with file attachment send successfully.";
                }
                else
                {
                    returnValue.Status  = false;
                    returnValue.Message = "Record not saved. Please try again";
                }
            }
            catch (Exception)
            {
                returnValue.Status  = false;
                returnValue.Message = "Error Sending Mail.";
            }

            return(Json(returnValue));
        }
Пример #2
0
        public JsonResult AccessRights(RightsModel model)
        {
            var returnValue = new JSONReturnValue();

            try
            {
                using (var dbContext = new DatabaseContext())
                {
                    int userId     = model.rights[0].UserId;
                    var userRights = dbContext.UserRights.Where(u => u.UserId == userId).ToList();
                    dbContext.UserRights.RemoveRange(userRights);

                    foreach (var item in model.rights)
                    {
                        var userRight = new UserRights();
                        userRight.UserId          = item.UserId;
                        userRight.RightsId        = item.RightsId;
                        userRight.Read            = item.Read;
                        userRight.Write           = item.Write;
                        userRight.CreatedDateTime = System.DateTime.Now;
                        userRight.CreatedBy       = 1;
                        dbContext.UserRights.Add(userRight);
                    }

                    dbContext.SaveChanges();
                }

                returnValue.Status = true;
                return(Json(returnValue));
            }
            catch (Exception ex)
            {
                Helper.Helper.LogFile(ex, Server.MapPath("~/Error"));
                returnValue.Status  = false;
                returnValue.Message = ex.Message;
                return(Json(returnValue));
            }
        }
Пример #3
0
        public JsonResult Delete(int UserId)
        {
            var returnValue = new JSONReturnValue();

            try
            {
                using (var dbContext = new DatabaseContext())
                {
                    var user = dbContext.Users.FirstOrDefault(u => u.UserId == UserId);
                    if (user != null)
                    {
                        dbContext.Users.Remove(user);

                        // Delete User Rights
                        var userRights = dbContext.UserRights.Where(u => u.UserId == UserId);
                        dbContext.UserRights.RemoveRange(userRights);

                        dbContext.SaveChanges();
                        ViewBag.Users       = this.GetUsers();
                        returnValue.Status  = true;
                        returnValue.Message = "Record has been deleted successfully";
                    }
                    else
                    {
                        returnValue.Status  = false;
                        returnValue.Message = "Record not found.";
                    }
                }
            }
            catch (Exception ex)
            {
                returnValue.Status  = false;
                returnValue.Message = "Some error in delete. Please check access or contact administrator.";
            }

            return(Json(returnValue));
        }
Пример #4
0
        public static string GenerateJSONReturnValue(object value)
        {
            JSONReturnValue returnValue = new JSONReturnValue(value);

            return JsonSerializer.ToJson(returnValue);
        }
Пример #5
0
        public static string GenerateJSONReturnValue(object value)
        {
            JSONReturnValue returnValue = new JSONReturnValue(value);

            return(Json.Stringify(returnValue, WebAppConfig.JsonDateFormat));
        }
Пример #6
0
        public static string GenerateJSONReturnValue(object value)
        {
            JSONReturnValue returnValue = new JSONReturnValue(value);

            return Json.Stringify(returnValue, WebAppConfig.JsonDateFormat);
        }
Пример #7
0
        public static string GenerateJSONReturnValue(object value)
        {
            JSONReturnValue returnValue = new JSONReturnValue(value);

            return(JsonSerializer.ToJson(returnValue));
        }