// PUT api/EmailServerConfig/5
        public HttpResponseMessage PutEmailServerAccount(int id, EmailServerAccount emailServerAccount)
        {
            if (!ModelState.IsValid)
            {
                FotoShoutUtils.Log.LogManager.Error(_logger, ModelState.Values.SelectMany(v => v.Errors));
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            if (id != emailServerAccount.EmailServerAccountId)
            {
                FotoShoutUtils.Log.LogManager.Error(_logger, string.Format(Errors.ERROR_EMAILSERVERCONFIG_UPDATE_IDSNOTIDENTICAL, id, emailServerAccount.EmailServerAccountId));
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            db.Entry(emailServerAccount).State = EntityState.Modified;

            try {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex) {
                FotoShoutUtils.Log.LogManager.Error(_logger, ex.ToString());
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }
            catch (Exception ex) {
                FotoShoutUtils.Log.LogManager.Error(_logger, ex.ToString());
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Exemple #2
0
        public ActionResult EmailServerConfiguration(EmailServerAccount model)
        {
            try {
                if (ModelState.IsValid)
                {
                    EmailServerAccount temp = fsWebService.EmailServerConfiguration(model);
                    if (temp == null && model.EmailServerAccountId == 0)
                    {
                        this.AddModelError(Errors.ERROR_EMAILSERVERCONFIG, _logger);
                    }
                    else
                    {
                        if (temp != null)
                        {
                            model = temp;
                        }
                        this.AddMessage(Constants.INFO_EMAILSERVERCONFIG_SUCCESS);
                    }
                }
                else
                {
                    this.AddModelError(ModelState.Values.SelectMany(v => v.Errors).ToList(), _logger);
                }
            }
            catch (Exception ex) {
                this.AddModelError(ex.Message, _logger, ex);
            }

            return(View(model));
        }
Exemple #3
0
 public ActionResult EmailServerConfiguration()
 {
     try {
         EmailServerAccount model = fsWebService.GetEmailServerConfiguration();
         return(View(model));
     }
     catch (HttpClientServiceException ex) {
         if (ex.StatusCode != System.Net.HttpStatusCode.NotFound)
         {
             this.AddModelError(ex.Message, _logger, ex);
         }
     }
     catch (Exception ex) {
         FotoShoutUtils.Log.LogManager.Debug(_logger, ex.ToString());
     }
     return(View());
 }
        // GET api/EmailServerConfig
        public EmailServerAccount GetEmailServerAccount()
        {
            EmailServerAccount emailServerAccount = null;

            try {
                emailServerAccount = db.EmailServerAccounts.Where(e => e.User.Id == CurrentUser.Id).SingleOrDefault();
            }
            catch (Exception ex) {
                FotoShoutUtils.Log.LogManager.Error(_logger, ex.ToString());
                this.GenerateException(HttpStatusCode.InternalServerError, ex.Message);
            }

            if (emailServerAccount == null)
            {
                this.GenerateException(HttpStatusCode.NotFound, "Email Server Account has not been configured yet.");
            }

            return(emailServerAccount);
        }
        // POST api/EmailServerConfig
        public HttpResponseMessage PostEmailServerAccount(EmailServerAccount emailServerAccount)
        {
            if (ModelState.IsValid)
            {
                emailServerAccount.User = db.Users.Find(CurrentUser.Id);
                db.EmailServerAccounts.Add(emailServerAccount);
                try {
                    db.SaveChanges();
                }
                catch (Exception ex) {
                    FotoShoutUtils.Log.LogManager.Error(_logger, ex.ToString());
                    throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
                }

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, emailServerAccount);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", null));
                return(response);
            }
            else
            {
                FotoShoutUtils.Log.LogManager.Error(_logger, ModelState.Values.SelectMany(e => e.Errors));
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
 public EmailServerAccount EmailServerConfiguration(EmailServerAccount model)
 {
     return((model.EmailServerAccountId != 0) ?
            Modify <EmailServerAccount>("EmailServerConfig/" + model.EmailServerAccountId, model, Constants.INFO_EMAILSERVERCONFIG, "PUT") :
            Modify <EmailServerAccount>("EmailServerConfig", model, Constants.INFO_EMAILSERVERCONFIG));
 }