public JsonResult Post(long?id, int groupId, string email, string firstname, string lastname) { var json = new JsonDataModel(); if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(firstname) || string.IsNullOrEmpty(lastname)) { json.result = ResultType.UnSuccess; json.message = "Lütfen tüm alanları doldurunuz"; } else { if (id > 0) { var postItem = _db.Contact.GetById(id); postItem.GroupId = groupId; postItem.Email = email; postItem.FirstName = firstname; postItem.LastName = lastname; _db.Contact.Edit(postItem); } else { var isExistContact = _db.Contact.All.Any(x => x.Email == email.ToLower() && x.GroupId == groupId); if (isExistContact == false && email.Length > 0 && UtilManager.EmailIsValid(email)) { var postItem = new Contact(); postItem.Email = email.ToLower(); postItem.GroupId = groupId; postItem.FirstName = firstname; postItem.LastName = lastname; postItem.CreateDate = DateTime.Now; _db.Contact.Add(postItem); json.result = ResultType.Success; } else { json.result = ResultType.UnSuccess; json.message = "Bu mail adresi grupta bulunuyor"; } } } return(Json(new { json }, JsonRequestBehavior.AllowGet)); }
// PUBLIC METHOD public ResultType Add(string email, string firstname, string lastname) { var groupId = _db.Group.All.OrderBy(x => x.Id).FirstOrDefault().Id; var isExistContact = _db.Contact.All.Any(x => x.Email == email.ToLower() && x.GroupId == groupId); if (isExistContact == false && email.Length > 0 && UtilManager.EmailIsValid(email)) { var postItem = new Contact(); postItem.Email = email.ToLower(); postItem.GroupId = groupId; postItem.FirstName = firstname; postItem.LastName = lastname; postItem.CreateDate = DateTime.Now; _db.Contact.Add(postItem); return(ResultType.Success); } else { return(ResultType.UnSuccess); } }